
import tableEdit  from '../../components/edit/tableEdit.vue'
import FuneralItemSelectShow  from '../../components/byg/FuneralItemSelectShow.vue'
const funeralMixin = {
   
    

    props:['dataField','listField','data','params','appid','isgm','extype','exkey'],
    name:'funeral-item-table',
    components: {
       tableEdit,
       FuneralItemSelectShow
    },
    data(){
        return{
            sCode:localStorage.getItem("sCode"),
            jmTitle:"减免金额",
            shTitle:"实收金额",
            showtable:false,
            amt_totals:'',
            sh_totals:'',
            yh_totals:"",
            jm_totals:'',
            bz_totals:'',
            gl_totals:"",
            gs_totals:"",
            sfItemData:[],
            hy_ex6:'',
            options: [],
            jmJson:[],
            hasJmJson:"",//已减免的减免项目名称合集
            value: '',
            drawer: false,
            direction: 'rtl',
            change:false,
            isJm:false,
            isCheckout:false,
            sz_ex42:"",
            c_ex77:"",
            sz_ex42_old:"",
            isSetGlf:"N",
            gm_dat3:"",
            gm_dat4:"",
            c_ex4:"",
            gm_id:"",
            sz_ex61s:"",
            c_ex60:"",//公墓的总优惠
            yh_totalsOld:"",
            firstTotal:"Y",
            depart:"",
            dw:"",
            outerVisible:false,
            isYtj:sessionStorage.getItem("isYtj"),
            isDialog:false,
            isFirst2:"Y",
            isPriceSelect:"N",
            sz_depart:"",
            sl_depart:"",
            addBtnType:"1",
            defaultClick:"N",
            isWarehouse:"N",
            tabs:[],
            isAdd:"Y",
            isDel:"Y",
            isShowJm:"Y",
            txItem:{},
            isShowDetail:"N",
            iscf:"N",//是否允许重复
            isCheckPrice:"N",//添加服务项目的时候，如果价格不同是否提示需要添加一个新的服务项目行
            postUrl:"byg/funeral/getFuneralSfItem",
            postUrlItem:"/byg/funeral/getFuneralSfMealItem",
            postUrlDp:"/byg/funeral/getSfItemDp",
            /*jmSet:{
                jmField:"",//减免字段
                jmText:"",//那个户籍地址享受减免
                jmTex2:""//减免名称
            }*/
            jmSet:[],
            isJmSet:false,
            selectItemName:{},
            selectItemId:{},
            validate:[],
            lt_dat1_old:"",
            lt_dat2_old:"",
            lt_name_old:"",
            lc_dat1_old:"",
            lc_dat2_old:"",
            groupName:sessionStorage.getItem("groupName"),
            isComputeLt:"N",
            glName:"单位金额",
            gsName:"第三方金额",
            scr_ex10:"",//里程
            carName:"",
            isFnjm:"N",//未成年人减半
            isFnjmAge:"",
            isRight:false,//页面是否靠右显示
            isLcHh:false,//是否根据火化日期算冷藏天数
            lcName:"",//冷藏的服务项目名字
            isComputeLc:true,
            isQBjm:false,//是否使用了全部减免
            isUseJm:true,//是否使用减免
            cfCheck:[],
            changeSetJm:false,
            setData:[],//赋值，就是选择了哪些服务项目要给哪个字段赋值
            compute:[],
            decimal:"",
            delset:[],
            replaceXM:[],
            kmtsxm:"",
            replaceUser:"",//替换添加人
            replaceUserObj:{},
            replaceXM2:[],//用于从套餐切换成普通项目的时候，删除了套餐项目，要添加回之前被替换的普通项目；昆明西郊使用
            blurChange:"N"
        }
    },
    
    created(){
       
       console.log(this.exkey,"this.exkey======sss====开始进入")
       /* if(this.dataField){
             this.showtable=true;
            this.tableData=this.data[this.dataField];
        }*/
        try{
            if(this.exkey.setData){
                this.setData=this.exkey.setData;
            }
        }catch(e){}
        try{
            if(this.exkey.blurChange){
                this.blurChange=this.exkey.blurChange;
            }
        }catch(e){}

        try{
            if(this.exkey.replaceXM){
                this.replaceXM=this.exkey.replaceXM;
            }
        }catch(e){}
        try{
            if(this.exkey.replaceXM2){
                this.replaceXM2=this.exkey.replaceXM2;
            }
        }catch(e){}
        try{
            if(this.exkey.replaceUser){
                this.replaceUser=this.exkey.replaceUser;
            }
        }catch(e){}
        try{
            if(this.exkey.del){
                this.delset=this.exkey.del;
            }
        }catch(e){}
        console.log(this.delset,"this.delset===================")
        try{
            if(this.exkey.compute){
                this.compute=this.exkey.compute;
            }
        }catch(e){}
        try{
            if(this.exkey.decimal){
                this.decimal=this.exkey.decimal;
            }
        }catch(e){}
        
        this.isJmSet=false;
        try{
            if(this.exkey.jmSet){
                this.jmSet=this.exkey.jmSet;
                if(this.jmSet.length>0){
                    for(let i=0;i<this.jmSet.length;i++){
                        let jmField=this.jmSet[i].jmField.split(".");
                        let v=this.data[jmField[0]][jmField[1]];
                        this.jmSet[i].jmFieldValue=v;
                    }
                }
            }
        }catch(e){}
        try{
            if(this.exkey.isUseJm&&this.exkey.isUseJm=="N"){
                this.isUseJm=false;
            }
        }catch(e){}
        try{
            if(this.exkey.cfCheck){
                this.cfCheck=this.exkey.cfCheck;//重复判断项目
            }
        }catch(e){}
        try{
            if(this.exkey.isRight){
                this.isRight=this.exkey.isRight=="Y" ? true:false;
            }
        }catch(e){}
        try{
            if(this.exkey.isLcHh){
                this.isLcHh=this.exkey.isLcHh=="Y" ? true:false;
            }
        }catch(e){}
        try{
            if(this.exkey.jmTitle){
                this.jmTitle=this.exkey.jmTitle;
            }
        }catch(e){}
        try{
            if(this.exkey.lcName){
                this.lcName=this.exkey.lcName;
            }
        }catch(e){}
        try{
            if(this.exkey.glName){
                this.glName=this.exkey.glName;
            }
        }catch(e){}
        try{
            if(this.exkey.isFnjm){
                this.isFnjm=this.exkey.isFnjm;
            }
        }catch(e){}
        try{
            if(this.exkey.isFnjmAge){
                this.isFnjmAge=this.exkey.isFnjmAge;
            }
        }catch(e){}
        try{
            if(this.exkey.gsName){
                this.gsName=this.exkey.gsName;
            }
        }catch(e){}

        try{
            if(this.exkey.isComputeLt){
                this.isComputeLt=this.exkey.isComputeLt;
            }
        }catch(e){}
        try{
            if(this.exkey.addBtnType){
                this.addBtnType=this.exkey.addBtnType;
            }
        }catch(e){}
        try{
            if(this.exkey.isShowJm){
                this.isShowJm=this.exkey.isShowJm;
            }
        }catch(e){}
        try{
            if(this.exkey.iscf){
                this.iscf=this.exkey.iscf;
            }
        }catch(e){}
        try{
            if(this.exkey.isAdd){
                this.isAdd=this.exkey.isAdd;
            }
        }catch(e){}
        
        try{
            if(this.exkey.isShowDetail){
                this.isShowDetail=this.exkey.isShowDetail;
            }
        }catch(e){}
        
        try{
            if(this.exkey.isDel){
                this.isDel=this.exkey.isDel;
            }
        }catch(e){}
        try{
            if(this.exkey.postUrl){
                this.postUrl=this.exkey.postUrl;
            }
        }catch(e){}

        try{
            if(this.exkey.postUrlDp){
                this.postUrlDp=this.exkey.postUrlDp;
            }
        }catch(e){}

        try{
            if(this.exkey.postUrlItem){
                this.postUrlItem=this.exkey.postUrlItem;
            }
        }catch(e){}

        
        
       //alert(this.exkey.postUrl+"=="+this.postUrl)
      //  alert(this.exkey.defaultClick)
        try{
            if(this.exkey.defaultClick){
                this.defaultClick=this.exkey.defaultClick;
            }
        }catch(e){}
        try{
            if(this.exkey.isWarehouse){
                this.isWarehouse=this.exkey.isWarehouse;
            }
        }catch(e){}
        try{
            if(this.exkey.tabs){
                this.tabs=this.exkey.tabs
            }
        }catch(e){}

        try{
            if(this.exkey.isCheckPrice){
                this.isCheckPrice=this.exkey.isCheckPrice
            }
        }catch(e){}

        try{
            if(this.data.szCar){
                this.scr_ex10=this.data.szCar.scr_ex10;
            }
        }catch(e){}
        try{
            this.isCheckout=(this.data["szInfo"].sz_ex29=="Y"||this.data["szInfo"].sz_ex29=="B") ? true:false;
        }catch(e){}
        try{
            console.log(this.compute,"this.computed=========")
            for(let i=0;i<this.data[this.dataField].length;i++){
                let szi_ex9=this.data[this.dataField][i].szi_ex9;
                let szi_ex1=this.data[this.dataField][i].szi_ex1;
                let szi_ex28=this.data[this.dataField][i].szi_ex28;
                let szi_ex2=Number(this.data[this.dataField][i].szi_ex2);
                if(szi_ex9=="车辆"){
                    this.carName=this.data[this.dataField][i].szi_ex1;
                }
                if(!this.isCheckout&&this.compute&&this.compute.length>0){//主要用于冷藏；按当前时间计算；南通殡仪馆
                    for(let h=0;h<this.compute.length;h++){
                        let name=this.compute[h].name;
                        let type=this.compute[h].type;
                        if(name==szi_ex1){
                            let startDate=this.compute[h].startDate.split(".");
                            let endDate=this.compute[h].endDate;
                            let endDate2=this.compute[h].endDate2;
                            if(endDate=="curDate"){
                                endDate=this.getNowDate();
                            }else{
                                let endDates=endDate.split(".");
                                let epid=endDates[0];
                                let ecid=endDates[1];
                                endDate=this.data[epid][ecid]
                            }
                            if(endDate2=="curDate"){
                                endDate2=this.getNowDate();
                            }else{
                                let endDates=endDate2.split(".");
                                let epid=endDates[0];
                                let ecid=endDates[1];
                                endDate2=this.data[epid][ecid]
                            }
                            if(endDate2&&endDate2.indexOf("1900-01-01")==-1){
                                endDate=endDate2;
                            }
                            let spid=startDate[0];
                            let scid=startDate[1];
                            startDate=this.data[spid][scid];
                            console.log("startDate========="+startDate+"="+endDate+"=="+spid+"=="+scid)
                            let day_=Math.floor(this.getDaysBetween(startDate.substring(0,10),endDate));
                           
                            if(type=="自然天数"){
                                day_++;
                            }
                            if(day_){
                                this.$set(this.data[this.dataField][i],"szi_ex4",day_);
                                this.$set(this.data[this.dataField][i],"szi_ex5",day_*szi_ex2);
                            }
                            
                        }
                       
                    }
                }
            }
        }catch(e){}
        try{
            if(this.data.lc){
                this.lc_dat1_old=this.data.lc.lc_dat1;
                this.lc_dat2_old=this.data.szInfo.sz_dat7;
            }
        }catch(e){}
        if(this.data.lt&&this.isComputeLt=="Y"){
            try{
                 
                 let lt_dat1=this.data.lt.lt_dat1;
                 let lt_dat2=this.data.lt.lt_dat2;
                 let lt_name="";
                 for(let i=0;i<this.data[this.dataField].length;i++){
                     if(this.data[this.dataField][i].szi_ex7=='礼厅'){
                         lt_name=this.data[this.dataField][i].szi_ex1;
                     }
                 }
                 this.lt_dat1_old=lt_dat1;
                 this.lt_dat2_old=lt_dat2;
                 this.lt_name_old=lt_name;
                }catch(e){}
            }
            
         try{
            if(this.data.szInfo){
                let sz_ex42=this.data.szInfo.sz_ex42;
                this.sz_ex42=sz_ex42;
                this.sz_ex42_old=sz_ex42;
                this.value=sz_ex42;
            }
            
         } catch(e){}
        try{
            //限制不能删除和新增
            if(this.exkey.validate){
                let isOk=false;
                this.validate=this.exkey.validate;
                for(let i=0;i<this.validate.length;i++){
                    let va=this.validate[i];
                    let field=va.field.split(".");
                    let opr=va.opr;
                    let vals=va.val
                    let val=this.data[field[0]][field[1]];
                    
                    if(opr=="等于"&&vals==val){
                        isOk=true;
                    }
                    if(opr=="不等于"&&vals!=val){
                        isOk=true;
                    }
                    if(opr=="等于"&&vals!=val){
                        isOk=false;
                    }
                    if(opr=="不等于"&&vals==val){
                        isOk=false;
                    }
                }
               
                if(isOk){
                    this.isAdd="N";
                    this.isDel="N"
                }
            }
        }catch(e){}
        try{
            if(this.data["gmInfo"])
                this.gm_id=(this.data["gmInfo"].gm_id)
        }catch(e){}
        try{
            if(this.exkey.isNotDepart=="Y")
                this.gm_id="";
        }catch(e){}
        try{
            this.sz_ex61s=this.data["szInfo"].sz_ex61;
        }catch(e){}
        try{
            this.sz_depart=this.data["szInfo"]["sz_depart"];
        }catch(e){}
        try{
            this.sl_depart=this.data["sl"]["sl_depart"];
        }catch(e){}
        try{
            if(this.data["yuyue"]["sz_dw"])
                this.dw=this.data["yuyue"]["sz_dw"];
            else
                this.dw=this.data["yuyue"]["sh_ex27"];
        }catch(e){}

         try{
             if(this.data["gmInfo"])
                this.c_ex77=(this.data["gmInfo"].c_ex77)
        }catch(e){}
       
        this.dingjin();
        this.loadJm();
        this.hy_ex6='';
        
        let hy_ex6="";
        try{
            hy_ex6=this.data.szInfo.hy_ex6;
        }catch(e){}
        let carNum="";
        try{
            if(this.data.szInfo.carNum){
                carNum=this.data.szInfo.carNum;

            }
        }catch(e){}
        try{
           
            if(this.sfItemData.length==0){
                if(!this.depart){
                    try{
                        if(this.data["szInfo"]["sz_depart"]){
                            this.depart=this.data["szInfo"]["sz_depart"]
                        }else if(this.exkey.departField){
                            this.depart=this.data[this.exkey.departPId][this.exkey.departField]
                        }
                    }catch(e){
                        try{
                            if(this.exkey.departField){
                                this.depart=this.data[this.exkey.departPId][this.exkey.departField]
                            }
                        }catch(e){}
                    }
                    
                }
                //alert(this.depart)
                this.$post(this.appid,this.postUrl,{gm_id:this.gm_id,depart:this.depart,dw:this.dw,type3:escape(this.extype)}).then(data=>{
                    this.sfItemData=[];
                    
                    for(let i=0;i<data.item.length;i++){
                        this.sfItemData.push(data.item[i]);
                    }
                    sessionStorage.setItem("sfItemData",JSON.stringify(this.sfItemData))
                    try{
                        if(this.data["szInfo"].sz_ex29&&this.data["szInfo"].sz_ex29!='Y'&&this.data["szInfo"].sz_ex29!='B'&&this.data["szInfo"].sz_ex23!='Y')
                            this.loadFirst();
                    }catch(e){}
                    //alert(hy_ex6)
                    if(hy_ex6)
                        this.loadFn(hy_ex6)
                    
                    this.loadCar(carNum)
                    this.loadGlf();
                    if(data.isPriceSelect){
                        this.isPriceSelect=data.isPriceSelect;
                    }
                
                })
            }else{
                if(hy_ex6)
                    this.loadFn(hy_ex6)
                this.loadCar(carNum)
                this.loadGlf();
            }
        }catch(e){}
        this.$parent.$el.getElementsByClassName("el-card__body")[0].style.paddingBottom="0";
        
    },
    mounted(){
        this.changeAmt();
        
    
    },
    methods:{
        replaceXMS(){
            
            console.log(this.replaceXM,"开始replacexm======================")
            if(this.replaceXM&&this.replaceXM.length>0){
                
                this.replaceXM.forEach(xm=>{
                    let isOk=false;
                    let isOk2=false;
                    let indexs=-1;
                    let indexs2=-1;
                    
                    this.data[this.dataField].forEach((item,index) => {
                        //console.log(item.szi_ex1+"="+xm.srcXM+"="+xm.destXM+"="+(item.szi_ex1==xm.srcXM)+"="+(item.szi_ex1==xm.destXM))
                        if(item.szi_ex1==xm.srcXM){
                            if(!item.szi_ex6||item.szi_ex6.indexOf(xm.remark)==-1){
                                isOk=true;
                                indexs=index;
                            }else if(xm.type=="thall"){
                                isOk=true;
                                indexs=index;
                            }
                                
                        }
                        if(item.szi_ex1==xm.destXM){
                            isOk2=true;
                            indexs2=index;
                        }

                    });
                    //console.log("isOk=="+isOk+"="+isOk2+"="+indexs+"="+xm.destXM+"=")
                    if(isOk&&isOk2){
                        if(xm.type=="th"&&indexs>=0){
                            let item=this.data[this.dataField][indexs];
                            console.log(item,"替换--------------")
                            if(Number(item.szi_ex4)<=Number(xm.scrNum)){
                                let items=this.data[this.dataField][indexs];
                                let items2=this.data[this.dataField][indexs2];

                                if(items.szi_ex51){
                                    items2.szi_ex51=items.szi_ex51;
                                    items2.szi_ex52=items.szi_ex52;
                                    items2.szi_ex53=items.szi_ex53;
                                    console.log(items2,"删除-----------------------")
                                    this.$set(this.data[this.dataField],indexs2,items2);
                                }
                               
                                this.$delete(this.data[this.dataField],indexs)


                              //  
                                console.log("删除完成-----------------------")
                                
                            }else{
                                let szi_ex2=Number(item.szi_ex2);
                                let szi_ex4=Number(item.szi_ex4)-Number(xm.scrNum);
                                let szi_ex5=szi_ex2*szi_ex4;
                                console.log(JSON.stringify(item),"szi_ex2========"+szi_ex2+"=="+szi_ex4+"=="+szi_ex5)
                                item.szi_ex4=szi_ex4;
                                item.szi_ex5=szi_ex5;
                                item.szi_ex6=item.szi_ex6+xm.remark;
                                this.$set(this.data[this.dataField],indexs,item);
                            }
                        }else if(xm.type=="thall"&&indexs>=0){
                            let item=this.data[this.dataField][indexs];
                            console.log(item,"替换2--------------")
                            let items=this.data[this.dataField][indexs];
                            let items2=this.data[this.dataField][indexs2];
                            items2.szi_ex2=items.szi_ex2;
                            items2.szi_ex5=items.szi_ex5;
                            items2.szi_ex6=items2.szi_ex6+"("+items.szi_ex6+")";
                            if(items.szi_ex51){
                                items2.szi_ex51=items.szi_ex51;
                                items2.szi_ex52=items.szi_ex52;
                                items2.szi_ex53=items.szi_ex53;
                                console.log(items2,"删除2-----------------------")
                                this.$set(this.data[this.dataField],indexs2,items2);
                            }
                            
                            this.$delete(this.data[this.dataField],indexs)


                            //  
                            console.log("删除完成2-----------------------")
                                
                            
                        }
                    }

                })
                
            }
        },
        initItemData(){
            for(let i=0;i<this.data[this.dataField].length;i++){
                //设置权限，不能修改，删除
                let sf_ex78=this.data[this.dataField][i].sf_ex78;
                if(sf_ex78&&this.groupName!="管理员"){
                    if((","+sf_ex78+",").indexOf(","+this.groupName+",")==-1){
                        this.data[this.dataField][i].isReadOnly='Y'
                    }
                }
            }
        },
        setJm(){
            if(!this.isUseJm){
                return;
            }
            console.log("setJm=============================="+this.value)
            console.log("this.value===="+this.value+"=="+this.sz_ex42_old+"=="+this.changeSetJm)
            if(this.value==this.sz_ex42_old){
                if(!this.changeSetJm)
                    return;
            }
            
            console.log("setJm==============================进入"+this.value)
            this.hasJmJson="";
            console.log(this.data)
            this.isJm=true;
            let isNotJm=true;
            this.selectItemName={};
            this.selectItemId={}
            let jmItems={}
            for(let i=0;i<this.data[this.dataField].length;i++){
                let datas=this.data[this.dataField][i];
                let szi_ex1=datas.szi_ex1;
                let szi_ex8=datas.szi_ex8;
                this.selectItemName[szi_ex1]=datas;
                this.selectItemId[szi_ex8]=datas;

                if(datas.szi_ex7=="减免"){
                    jmItems[szi_ex8]=datas;
                }
            }
            
            //减免
            if(this.value){
                let jmJson={};
                for(let i=0;i<this.jmJson.length;i++){
                    if(this.jmJson[i].name==this.value){
                        jmJson=this.jmJson[i];
                       
                    }
                }
                for(let i=0;i<this.jmJson.length;i++){
                    //this.value就是选择的减免类型
                    let isOk=false;
                    if(this.jmJson[i].name==this.value){
                       // jmJson=this.jmJson[i];
                        isOk=true;
                    }
                    let jmJson_=this.jmJson[i];
                    console.log("isOk================"+isOk)
                    if(jmJson_.item&&!isOk){
                        for(let j=0;j<jmJson_.item.length;j++){
                            let szi_ex5_=Number(jmJson_.item[j].szi_ex5);
                            let szi_ex18=jmJson_.item[j].szi_ex18;
                            let szi_ex7=jmJson_.item[j].szi_ex7;
                            let isOk_=true;
                           
                            /*if(jmJson&&jmJson.item){
                                for(let jj=0;jj<jmJson.item.length;jj++){
                                    let szi_ex18__=jmJson.item[jj].szi_ex18;
                                   
                                    if(szi_ex18__&&szi_ex18__==szi_ex18){
                                        isOk_=false;
                                    }
                                }
                            }*/
                            if(isOk_){
                            //if(szi_ex5_>=0&&isOk_){
                               
                                let index=-1;
                                while(index!=-2){
                                    for(let i=0;i<this.data[this.dataField].length;i++){
                                        let datas=this.data[this.dataField][i];
                                        let szi_ex18_=datas.szi_ex18;
                                        let szi_ex15_=datas.szi_ex15;
                                        let isOk__=true;
                                        if(szi_ex15_&&szi_ex15_==jmJson_.name){
                                            index=i;
                                        }
                                        //if(szi_ex18_==szi_ex18&&szi_ex18!=""&&isOk__)
                                         //   index=i;
                                    }
                                    if(index!=-1){
                                        this.$delete(this.data[this.dataField],index);
                                        
                                        index=-1;
                                    }else{
                                        index=-2;
                                    }
                                    
                                }
                                
                            
                                
                            }
                        }
                    }
                    
                    
                }
              
                //减免的json
                if(jmJson&&jmJson.item&&jmJson.item.length>0){
                    
                    let items=[];
                    let dels=[]
                    console.log(this.value+"=="+this.sz_ex42_old,"sz_ex2==============")
                    //把这个减免套餐必填项目带入
                    if(this.value!=this.sz_ex42_old){
                        console.log("sz_ex42进入==========")
                        for(let j=0;j<jmJson.item.length;j++){
                            let szi_ex1=jmJson.item[j].szi_ex1;
                            let szi_ex5_=Number(jmJson.item[j].szi_ex5);
                            let szi_ex18=jmJson.item[j].szi_ex18;
                            let szi_ex7=jmJson.item[j].szi_ex7;
                            let szi_ex8=jmJson.item[j].szi_ex8;
                            //如果金额大于0，则该项目的sf_ex37必须录入该减免类型名称
                            //这个会判断金额大于0，是因为在减免类型的子表中有些实际不是减免项目，是需要根据选择的减免类型必选项目
                            if(szi_ex5_>=0){
                                /*let index=-1;
                                while(index!=-2){
                                    for(let i=0;i<this.data[this.dataField].length;i++){
                                        let datas=this.data[this.dataField][i];
                                        let szi_ex18_=datas.szi_ex18;
                                        if(szi_ex18_==szi_ex18&&szi_ex18!="")
                                            index=i;
                                    }
                                    if(index!=-1){
                                        this.$delete(this.data[this.dataField],index);
                                        
                                        dels.push(index);
                                        index=-1;
                                    }else{
                                        index=-2;
                                    }
                                    
                                }*/
                            let isOk_=true; 
                            for(let i=0;i<this.data[this.dataField].length;i++){
                                    let datas=this.data[this.dataField][i];
                                    let szi_ex8_=datas.szi_ex8;
                                    if(szi_ex8==szi_ex8_)
                                        isOk_=false;
                                }
                                if(isOk_){
                                    jmJson.item[j].szi_ex15=jmJson.name;
                                   
                                    items.push(JSON.parse(JSON.stringify(jmJson.item[j])));
                                }
                                
                            }
                            
                        }
                    
                        let len=this.data[this.dataField].length;
                        for(let i=0;i<items.length;i++){
                            this.$set(this.data[this.dataField],len,items[i]);  
                            len++;
                        }
                        this.sz_ex42_old=this.value;
                    }
                    console.log(this.data[this.dataField],"itemssss=====================ss===")
                    let itemss=[];
                    let jms={}
                    let isBZYPJM=false;
                    
                    //有些正数项目对应一个负数减免，但又有优先级并且互斥（看价格）
                    let notJmItem={};
                    this.data[this.dataField].forEach((itemsss,ii)=>{
                        let sf_ex79=itemsss.sf_ex79;
                        if(sf_ex79){
                            let sf_ex79s=sf_ex79.split(",");
                            let amts=0;
                            for(let hh=0;hh<sf_ex79s.length;hh++){
                                if(this.selectItemName[sf_ex79s[hh]]){
                                    let itemssss=this.selectItemName[sf_ex79s[hh]];
                                    amts+=Number(itemssss.szi_ex5);
                                }
                                
                            }
                            if(Number(itemsss.szi_ex5)<=amts){
                                notJmItem[itemsss.szi_ex8]="Y"
                            } else{
                                for(let hh=0;hh<sf_ex79s.length;hh++){
                                    if(this.selectItemName[sf_ex79s[hh]]){
                                        let itemssss=this.selectItemName[sf_ex79s[hh]];
                                        notJmItem[itemssss.szi_ex8]="Y"
                                    }
                                   
                                }
                            }
                        }
                    });
                    for(let i=0;i<this.data[this.dataField].length;i++){
                        let itemss__=this.data[this.dataField][i];
                        let szi_ex8=this.data[this.dataField][i].szi_ex8;
                        let szi_ex2=Number(this.data[this.dataField][i].szi_ex2);
                        let szi_ex4=Number(this.data[this.dataField][i].szi_ex4);
                        let szi_ex5=Number(this.data[this.dataField][i].szi_ex5);
                        let szi_ex18=this.data[this.dataField][i].szi_ex18;
                        let szi_ex37_=this.data[this.dataField][i].szi_ex37;
                        let sf_ex41=this.data[this.dataField][i].szi_ex20;//正数项目的最高单价减免
                        console.log("sf_ex41===========1="+sf_ex41)
                        let isOk=false;
                        let isOk2=true;
                        let isOk3=true;
                        let item={};
                        let isCover=false;
                        this.change=true;
                        //console.log("szi_ex1====="+this.data[this.dataField][i].szi_ex1+"=="+szi_ex18)
                        
                        let isBZYPJMSave=false;
                        for(let j=0;j<jmJson.item.length;j++){
                            let szi_ex1=jmJson.item[j].szi_ex1;
                            let szi_ex8=jmJson.item[j].szi_ex8;
                            let szi_ex5_=Number(jmJson.item[j].szi_ex5);
                            let sfm_ex4=jmJson.item[j].sfm_ex4;
                            let sf_ex75=jmJson.item[j].sf_ex75;
                            let sf_ex76=jmJson.item[j].sf_ex76
                            let sf_ex41jm=jmJson.item[j].sf_ex41;//减免项目里的单价减免
                            if(szi_ex1==szi_ex18){
                                isNotJm=false;
                                this.sz_ex42_old=this.value;
                               // console.log("szi_ex1=="+szi_ex1+"="+szi_ex5_+"="+szi_ex5);
                                isOk=true;
                                item=JSON.parse(JSON.stringify(jmJson.item[j]));
                                //判断减免项目是否已经结账
                                for(let i=0;i<this.data[this.dataField].length;i++){
                            
                                    let szi_ex1_=this.data[this.dataField][i].szi_ex1;
                                    let szi_ex37=this.data[this.dataField][i].szi_ex37;//已结账
                                    if(szi_ex1_==szi_ex18&&szi_ex37=="Y"&&szi_ex37_=="Y"){//如果正数项目换了，减免项目也得重新计算
                                        isOk2=false;
                                    }
                                    
        
                                }
                                
                                //保存所有有用的减免，然后for循环后删除所有无用的减免（正数项目已经删除掉了）
                                jms[item.szi_ex8]=true;
                                console.log("sf_ex76=叠加减免===="+sf_ex76+":"+szi_ex1+":"+itemss__.szi_ex1)
                                if(sf_ex76){//叠加项目减免，并且有优先级，需要在减免项目里的sf_ex41赋值最大减免金额
                                    item.szi_ex4="1";
                                    let sf_ex41jm_=0;
                                    let sf_ex41jm_2=Number(sf_ex41jm);
                                    if(sf_ex41jm!=''){
                                        sf_ex41jm_=Number(sf_ex41jm);
                                    }else{
                                        sf_ex41jm_=szi_ex5_;
                                    }
                                    let jmamt=0;
                                    let names="";

                                    if(sf_ex76=="丧葬用品"){

                                        //console.log("sf_ex76============"+sf_ex76+"=="+isBZYPJM)
                                        if(!isBZYPJM){
                                            isBZYPJM=true;
                                            isBZYPJMSave=true;
                                            
                                            this.data[this.dataField].forEach((itemsss,ii)=>{
                                                let isOkJm=true;
                                                let sf_ex79=itemsss.sf_ex79;
                                                
                                                console.log("sf_ex79========"+sf_ex79+"=="+itemsss.szi_ex1+"=="+isOkJm)
                                                if(notJmItem[itemsss.szi_ex8]=="Y"){
                                                    isOkJm=false;
                                                }
                                                if(!isOkJm){//有优先级更高的减免项目，源项目的减免字段要置空
                                                    let item__=itemsss;
                                                    item__.szi_ex42="";
                                                }
                                                if(isOkJm){
                                                    if(itemsss.szi_ex18==szi_ex1&&sf_ex41jm_<0){
                                                        let name=itemsss.szi_ex1;
                                                        
                                                        names=names=="" ? name:names+","+name;
                                                       // console.log("name===="+name)
                                                        let item__=itemsss;
                                                        let szi_ex5__=Number(item__.szi_ex5);//项目总金额
                                                        let szi_ex4__=Number(item__.szi_ex4);//项目总数量
                                                        let szi_ex20__=Number(item__.szi_ex20);//项目里的单价减免

                                                        //console.log("szi_ex20__----"+szi_ex20__)
                                                        if(szi_ex20__>0){//正数就是说每个最多减免多少；
                                                            szi_ex5__=szi_ex4__*szi_ex20__
                                                        }else if(szi_ex20__<0&&szi_ex20__>-szi_ex5__){
                                                            szi_ex5__=-szi_ex20__;
                                                        }
                                                       // console.log("szu_ex5===="+szi_ex5__)
                                                        if(sf_ex41jm_>-szi_ex5__&&sf_ex41jm_<0){
                                                            jmamt=jmamt+sf_ex41jm_;
                                                            
                                                            item__.szi_ex42=sf_ex41jm_.toFixed(2);
                                                            sf_ex41jm_=0;
        
                                                            if(sf_ex75=='jm'&&!this.txItem[item.szi_ex8]){
                                                                this.txItem[item.szi_ex8]=true
                                                                this.$message.error('项目【'+item__.szi_ex1+"】金额超出了减免金额");
                                                            
                                                            }
                                                        }else{
                                                            sf_ex41jm_=sf_ex41jm_+szi_ex5__;//还剩多少可以减免的
                                                            jmamt=jmamt-szi_ex5__;
                                                            item__.szi_ex42=-szi_ex5__.toFixed(2);
                                                            
                                                        }
                                                    }else if(itemsss.szi_ex18==szi_ex1){
                                                        let item__=itemsss;
                                                        item__.szi_ex42="";
                                                    }
                                                }
                                                
                                            
                                            })
                                            //if(isOkJm){
                                                console.log("jmamt============"+jmamt)
                                                item.szi_ex15=names;
                                                item.szi_ex2=jmamt.toFixed(2);
                                                item.szi_ex5=jmamt.toFixed(2);
                                                if(!item.szi_ex13)
                                                    item.szi_ex13=this.params;
                                                if(this.extype&&!item.szi_ex13){
                                                    item.szi_ex13=this.extype;
                                                }
                                                //alert(this.isShowJm)
                                                if(this.isShowJm=="N"){
                                                    item.isshow="N"
                                                }
                                                console.log(item,"叠加套餐===============")
                                            //}
                                            
                                        }else{
                                            isOk3=false;
                                        }
                                        
                                    }else{
                                        let sf_ex76s=sf_ex76.split(",");

                                        let jmnum="1"
                                        let isnum=false;
                                        let szi_ex20__old="";
                                        let jmindex=0;
                                        for(let h=0;h<sf_ex76s.length;h++){
                                            let name=sf_ex76s[h]
                                            
                                            if(this.selectItemName[name]&&sf_ex41jm_<0){
                                                names=names=="" ? name:names+","+name;
                                                console.log("name===="+name)
                                                let item__=this.selectItemName[name];
                                                let szi_ex5__=Number(item__.szi_ex5);//项目总金额
                                                let szi_ex4__=Number(item__.szi_ex4);//项目总数量
                                                let szi_ex20__=Number(item__.szi_ex20);//项目里的单价减免
                                                jmindex++;
                                                console.log("szi_ex0====="+szi_ex20__)
                                                if(szi_ex20__>0){
                                                    szi_ex5__=szi_ex4__*szi_ex20__//单价减免，就是说正数项目可能一天60；但减免一天只减免30
                                                    //用于修复；数量一直是1的情况
                                                    jmnum=szi_ex4__;
                                                    if(!szi_ex20__old){
                                                        szi_ex20__old=szi_ex20__
                                                    }else if(szi_ex20__old!=szi_ex20__){
                                                        isnum=false;
                                                    }
                                                }else if(szi_ex20__<0&&szi_ex20__>-szi_ex5__){
                                                    szi_ex5__=-szi_ex20__;
                                                }
                                                if(szi_ex20__==0){
                                                    isnum=false;
                                                }
                                                console.log("szi_ex5==="+szi_ex5__)
                                                if(sf_ex41jm_>-szi_ex5__&&sf_ex41jm_<0){
                                                    
                                                    jmamt=jmamt+sf_ex41jm_;
                                                    
                                                    item__.szi_ex42=sf_ex41jm_;
                                                    sf_ex41jm_=0;

                                                    //正数金额超过了减免金额最大金额；则判断一下是不是最大减免金额除最大减免单价金额，能不能除尽；能除尽数量就不在设置成1
                                                    if(isnum&&sf_ex41jm_2%szi_ex20__old==0){
                                                        jmnum=-sf_ex41jm_2/szi_ex20__old;
                                                        console.log("jmnum==============="+jmnum+"=="+sf_ex41jm_2)

                                                    }else{
                                                        isnum=false;
                                                    }

                                                    if(sf_ex75=='jm'&&!this.txItem[item.szi_ex8]){
                                                        this.txItem[item.szi_ex8]=true
                                                        this.$message.error('项目【'+item__.szi_ex1+"】金额超出了减免金额");
                                                    
                                                    }
                                                }else{
                                                    sf_ex41jm_=sf_ex41jm_+szi_ex5__;//还剩多少可以减免的
                                                    jmamt=jmamt-szi_ex5__;  //因为多个项目合并减免的，多个正数项目对应一个减免项目
                                                    item__.szi_ex42=-szi_ex5__;
                                                    
                                                }
                                            }else if(this.selectItemName[name]){
                                                let item__=this.selectItemName[name];
                                                item__.szi_ex42="";
                                            }
                                        }

                                        item.szi_ex15=names;
                                        item.szi_ex2=jmamt;
                                        item.szi_ex5=jmamt;
                                        //有两个及以上减免，数量就强制是1；
                                        if(jmindex>1){
                                            isnum=false;
                                        }
                                        
                                        console.log("isnum====="+isnum+"==="+jmamt+"=="+names+"==="+szi_ex20__old+"=="+jmnum+"=="+jmindex)
                                        if(isnum){
                                            item.szi_ex2=-szi_ex20__old
                                            item.szi_ex4=jmnum;
                                        }else{
                                            item.szi_ex4="1"
                                        }
                                        if(!item.szi_ex13)
                                            item.szi_ex13=this.params;
                                        if(this.extype&&!item.szi_ex13){
                                            item.szi_ex13=this.extype;
                                        }
                                        //alert(this.isShowJm)
                                        if(this.isShowJm=="N"){
                                            item.isshow="N"
                                        }
                                        console.log(item,"叠加套餐===============")
                                    }
                                    
                                   
                                }else{
                                    //减免项目只减免一次；如果有减免两个项目的走上面if语句
                                    if((","+this.hasJmJson+",").indexOf(","+item.szi_ex1+",")!=-1){
                                        isOk3=false;
                                        continue;
                                    }
                                   
                                    this.hasJmJson=this.hasJmJson=="" ? item.szi_ex1:this.hasJmJson+","+item.szi_ex1;
                                    item.szi_ex15=jmJson.name;
                                    console.log("sfm_ex4================"+sfm_ex4)
                                    if(sfm_ex4&&sfm_ex4!=undefined){//目前只有淮安永思源有按比例减免
                                        sfm_ex4=sfm_ex4.replace("%","");
                                        sfm_ex4=Number(sfm_ex4)/100;
                                        if(this.isgm=='Y'){
                                            let c_ex77=this.data["gmInfo"].c_ex77;
                                            if(c_ex77){
                                                sfm_ex4=Number(c_ex77.replace("%",""))/100;
                                            }
                                        }
                                        item.szi_ex4="1";
                                        item.szi_ex2=-szi_ex2*sfm_ex4;
                                        item.szi_ex5=-szi_ex5*sfm_ex4;
                                    }else if(sf_ex41!=''&&sf_ex41!=undefined){
                                        sf_ex41=Number(sf_ex41);//这个就是最多的减免金额，在收费项目里输入减免金额则不能大于他
                                        console.log("sf_ex41========================"+sf_ex41+"=="+szi_ex1+"=="+szi_ex8)
                                        if(sf_ex41>-szi_ex5&&sf_ex41<0){
                                            item.szi_ex4="1";
                                            item.szi_ex2=sf_ex41;
                                            item.szi_ex5=sf_ex41;
                                            if(sf_ex75=='jm'&&!this.txItem[item.szi_ex8]){
                                                this.txItem[item.szi_ex8]=true
                                                this.$message.error('项目【'+itemss__.szi_ex1+"】金额超出了减免金额");
                                            
                                            }
                                        }else{
                                            
                                            item.szi_ex2=-szi_ex2;
                                            item.szi_ex4=szi_ex4;
                                            item.szi_ex5=-szi_ex5;
                                        }
                                    }else{
                                        console.log("szi_ex5===="+szi_ex5+"=="+szi_ex5_+"=="+sf_ex75+"="+szi_ex1)
                                        if(szi_ex5_>-szi_ex5&&szi_ex5_<0){
                                            console.log("ssssssssssss")
                                            item.szi_ex4="1";
                                            item.szi_ex2=szi_ex5_;
                                            item.szi_ex5=szi_ex5_;
                                            if(sf_ex75=='jm'&&!this.txItem[item.szi_ex8]){
                                                console.log("11111111111111")
                                                this.txItem[item.szi_ex8]=true
                                                this.$message.error('项目【'+itemss__.szi_ex1+"】金额超出了减免金额");
                                            
                                            }
                                            
                                        }else{
                                            
                                            item.szi_ex2=-szi_ex2;
                                            item.szi_ex4=szi_ex4;
                                            item.szi_ex5=-szi_ex5;
                                        }
                                    }
                                    
                                    if(!item.szi_ex13)
                                        item.szi_ex13=this.params;
                                    if(this.extype&&!item.szi_ex13){
                                        item.szi_ex13=this.extype;
                                    }
                                    //alert(this.isShowJm)
                                    if(this.isShowJm=="N"){
                                        item.isshow="N"
                                    }
                                    if(isOk2)
                                        itemss__.szi_ex42=item.szi_ex5;
                                }
                                
                                //this.$refs.tableEditss.removeItemByName(item.szi_ex1);   
                                continue;
                               
                            }

                        }
                        console.log("isOks3=========="+isOk3)
                        if(!isOk3){
                            continue;
                        }
                        let index=-1;
                        let item_={}
                        for(let i=0;i<this.data[this.dataField].length;i++){
                            
                            let szi_ex1=this.data[this.dataField][i].szi_ex1;
                            let szi_ex37=this.data[this.dataField][i].szi_ex37;//已结账
                            if(szi_ex1==szi_ex18){
                                isCover=true;
                                index=i;
                                item_=this.data[this.dataField][i];;
                                if(szi_ex37=="Y"&&szi_ex37_=="Y"){
                                    item_=null;
                                }
                            }
                                


                        }
                        //除了上面判断是否在data存在外，还需要在items里判断
                        if(!isCover){
                            for(let i=0;i<itemss.length;i++){
                            
                                let szi_ex1=itemss[i].szi_ex1;
                                if(szi_ex1==szi_ex18){
                                    isCover=true;
                                    //index=i;
                                    isOk2=false;
                                    item_=null;
                                }
                                    
    
    
                            }
                        }
                        
                        console.log("isOk========"+isOk+"="+isCover)
                        console.log(item_);
                        if(isOk&&isCover){
                             if(item_){
                                if(Number(item_.szi_ex2)!=Number(item.szi_ex2)||Number(item_.szi_ex4)!=Number(item.szi_ex4)||Number(item_.szi_ex5)!=Number(item.szi_ex5)){
                                    /*this.$refs.tableEditss.setData(index,'szi_ex5',item.szi_ex5); 
                                    this.$refs.tableEditss.setData(index,'szi_ex2',item.szi_ex2); 
                                    this.$refs.tableEditss.setData(index,'szi_ex4',item.szi_ex4); */
                                    console.log("isOkCover=============="+isOk+"==="+isCover+"=="+item.szi_ex1)  
                                    console.log("isOkCover=============="+item_.szi_ex2+"==="+item.szi_ex2)  
                                    console.log("isOkCover=============="+item_.szi_ex4+"==="+item.szi_ex4)  
                                    console.log("isOkCover=============="+item_.szi_ex5+"==="+item.szi_ex5) 
                                    item.szi_id=item_.szi_id; 
                                    item.szi_mainid=item_.szi_mainid; 
                                    item.key_field=item_.key_field;
                                    this.$set(this.data[this.dataField],index,item);   
                                }
                             }
                            
                            
                        }else if(isOk)
                          
                            //this.$refs.tableEditss.addItem(JSON.stringify(item));
                            itemss.push(item);
                            console.log(item)
                            console.log("isJmIk========================"+isOk)
                        if(!isOk){
                            itemss__.szi_ex42="";
                        }
                    }
                    
                    for(let i=0;i<itemss.length;i++){
                        this.$set(this.data[this.dataField],this.data[this.dataField].length,itemss[i])
                    }
                    console.log(jms,"jms==================")
                    //删除无用的减免（正数项目已经被删除;只删除负数，在减免套餐里可能有正数金额）
                    let delItems=[]
                    for(let j=0;j<jmJson.item.length;j++){
                        let szi_ex8=jmJson.item[j].szi_ex8;
                        let szi_ex2=Number(jmJson.item[j].szi_ex2);

                        delete jmItems[szi_ex8]
                        console.log("szi_ex8=="+jmJson.item[j].szi_ex1+"=="+this.selectItemId[szi_ex8])
                        if(this.selectItemId[szi_ex8]&&!jms[szi_ex8]&&szi_ex2<0){
                            delItems.push(szi_ex8)
                        }
                    }
                    //切换减免类型的时候，有些减免项目可能不存在了，在循环jmJson的时候会有遗漏
                    for(let key in jmItems){
                        delItems.push(key)
                    }
                    console.log(delItems,"删除减免项目================")
                    for(let i=0;i<delItems.length;i++){
                        let szi_ex8=delItems[i];
                        let index=-1;
                        for(let j=0;j<this.data[this.dataField].length;j++){
                            let datas=this.data[this.dataField][j];
                            console.log("删除项目==============="+datas.szi_ex1)
                            if(szi_ex8==datas.szi_ex8){
                                index=j;
                                break;
                            }
                        }
                        if(index!=-1){
                            this.$delete(this.data[this.dataField],index);
                        }
                    }
                    //删除无用的减免（正数项目已经被删除）


                }
            }

            console.log("isNotJm================="+isNotJm)
            if(isNotJm){//去掉减免
                console.log(this.value+"=="+this.sz_ex42_old+"==sz_ex42")
                if(this.value!=this.sz_ex42_old){
                    this.sz_ex42_old=this.value;
                    let isOk=true;
                    console.log("删除减免项目======")
                    while(isOk){
                        let jmIndex=-1;
                        let isOk2=false;
                        for(let i=0;i<this.data[this.dataField].length;i++){
                            let szi_ex7=this.data[this.dataField][i].szi_ex7;
                            if(szi_ex7=="减免"){
                                jmIndex=i;
                                isOk2=true;
                                break;
                            }
                        }
                        this.$delete(this.data[this.dataField],jmIndex);
                        if(!isOk2){
                            isOk=false;
                        }
                    }

                    for(let i=0;i<this.data[this.dataField].length;i++){
                        let itemss__=this.data[this.dataField][i];
                        itemss__.szi_ex42="";
                    }
                }
               
                 
            }
            this.$nextTick(function () {
                // Code that will run only after the
                // entire view has been rendered
                 this.isJm=false;
            })
            
        },
        loadJm(){
            this.$post(this.appid,"byg/funeral/getFuneralSfItemJm",{gm_id:this.gm_id}).then(data=>{
                this.jmJson=data;
                this.options=[];
                let option_={};
                option_.label="请选择";
                option_.value="";
                this.options.push(option_)
                for(let i=0;i<this.jmJson.length;i++){
                    let option={};
                    option.label=this.jmJson[i].name;
                    option.value=this.jmJson[i].name;
                    this.options.push(option);
                }
                
            });
        },
        removeItemTc(data){
             let item=JSON.parse(data);
             let szi_ex8=item.szi_ex8;
             let isOk=true;
             while(isOk){
                 let isOk2=false;
                 for(let i=0;i<this.data[this.dataField].length;i++){
                    let row=this.data[this.dataField][i];
                    if(row.szi_ex31=="Y"&&row.szi_ex32==szi_ex8){
                        this.$delete(this.data[this.dataField],i);
                        isOk2=true;
                        break;
                    }
                }
                if(!isOk2){
                    isOk=false;
                }
             }
             
        },
        setDataCheck(){
            console.log(this.setData,"this.setData=========")
            let setList={};
            if(this.setData&&this.setData.length>0){
                for(let i=0;i<this.data[this.dataField].length;i++){
                    let d=this.data[this.dataField][i]
                    for(let j=0;j<this.setData.length;j++){
                        let field=this.setData[j].field;
                        let val=this.setData[j].val;
                        let setField=this.setData[j].setField.split(".");
                        let srcField=this.setData[j].srcField
                        let setVal=this.setData[j].setVal
                        let pId=setField[0];
                        let cId=setField[1]
                        console.log(d[field],"field====="+pId+"="+cId)
                        console.log(d[field]+"=="+val,"fields======")
                        if(d[field]==val){
                            
                            if(setVal){
                                this.$set(this.data[pId],cId,setVal)
                                setList[cId]="Y";
                            }else{
                                let srcs=srcField.split(",");
                                let vals="";
                                for(let m=0;m<srcs.length;m++){
                                    vals=vals+d[srcs[m]];
                                }
                                console.log("src============================"+vals)
                                this.$set(this.data[pId],cId,vals)
                                setList[cId]="Y";
                            }
                            
                        }
                    }
                }
                for(let j=0;j<this.setData.length;j++){
                    let field=this.setData[j].field;
                    let val=this.setData[j].val;
                    let setField=this.setData[j].setField.split(".");
                    let srcField=this.setData[j].srcField
                    let pId=setField[0];
                    let cId=setField[1]
                    if(!setList[cId]){
                        this.$set(this.data[pId],cId,"")
                    }
                }
            }
           
        },
        removeItem(data){
            console.log("removeItem==="+data)
            let item=JSON.parse(data);
            let id=item.id;
            let num=item.num;
            let szi_ex31="";
            let pId="";
            if(item.szi_ex31){
               szi_ex31= item.szi_ex31;
            }
            if(item.pId){
                pId=item.pId;
            }

            let isDelete=false;
            let index=-1;
            if(item.sf_ex24=="是"||item.sf_ex24=="A"){
               
                this.$post("bygex",this.postUrlItem,{sId:id}).then(data=>{
                       
                        if(data.length>0){
                            for(let row_ of data){
                                try{
                                  let data_={};
                                  data_.id=row_.szi_ex8;
                                  data_.num=num;
                                  data_.sf_ex24="";
                                  if(item.sf_ex24=="A"){
                                      data_.szi_ex31="Y";
                                      data_.pId=id;
                                  }
                                    
                                  this.removeItem(JSON.stringify(data_))
                                }catch(e){}
                               
                            }
                            //this.changeAmt();
                        }
                    });
            
            }
            if(item.sf_ex24!="是"){
                for(let i=0;i<this.data[this.dataField].length;i++){
                    let szi_ex31_=this.data[this.dataField][i].szi_ex31;
                    let szi_ex32_=this.data[this.dataField][i].szi_ex32;
                    if(this.data[this.dataField][i].szi_ex8==id){
                        if(szi_ex31=="Y"&&szi_ex31_!="Y"){
                            continue;
                        }
                        if(szi_ex31!="Y"&&szi_ex31_=='Y'){
                            continue;
                        }
                        if(szi_ex31=="Y"&&pId!=szi_ex32_){
                            continue;
                        }
                        if(num>0){
                            let datas=this.data[this.dataField][i];
                            let szi_ex2=datas.szi_ex2;
                            let szi_ex5=num*szi_ex2;
                            datas.szi_ex4=num;
                            datas.szi_ex5=szi_ex5;
                            
                            this.$set(this.data[this.dataField],i,datas);
                        }else{
                            index=i;
                            isDelete=true;
                        }
                    
                    }
                }
                if(isDelete){
                    this.$delete(this.data[this.dataField],index);
                }
            }
            this.setDataCheck();
        },
        addItems(data){

            let itemType=data.type;
            let isFg=data.isFg;
            let name=data.name;
            let name2=data.name2;
            let nameType="";
            if(!name2){
                name2=name;
            }
            if(data.nameType){
                nameType=data.nameType;
            }
            let row=null;
            for(let i=0;i<this.sfItemData.length;i++){
                let szi_ex1=this.sfItemData[i].szi_ex1;
                let szi_ex7=this.sfItemData[i].szi_ex7;
                if(itemType){
                    if(szi_ex1==name&&itemType==szi_ex7){
                        row=this.sfItemData[i];
                    }
                }else{
                    if(szi_ex1==name){
                        row=this.sfItemData[i];
                    }
                }
                
            }
           
            let isOk=true;
            let szi_ex27="";
            if(row!=null){
                for(let i=0;i<this.data[this.dataField].length;i++){
                    let szi_ex1=this.data[this.dataField][i].szi_ex1;
                    let szi_ex7=this.data[this.dataField][i].szi_ex7;
                    let szi_ex14=this.data[this.dataField][i].szi_ex14;
                    if(itemType){
                        if(nameType){
                            if(szi_ex1==row.szi_ex1&&itemType==szi_ex7&&nameType==szi_ex14){
                                isOk=false;
                            }
                        }else{
                             if(szi_ex1==row.szi_ex1&&itemType==szi_ex7){
                                isOk=false;
                            }
                        }
                       
                    }else{
                        if(szi_ex1==row.szi_ex1){
                            isOk=false;
                        }
                    }
                    
                }
            
            }
            if(isFg){
                isOk=true;
            }
            if(row!=null&&isOk){
                if(itemType){
                    let index=-1;
                    for(let i=0;i<this.data[this.dataField].length;i++){
                        let szi_ex7=this.data[this.dataField][i].szi_ex7;
                        let szi_ex1=this.data[this.dataField][i].szi_ex1;
                        let szi_ex14=this.data[this.dataField][i].szi_ex14;
                        let szi_ex27_=this.data[this.dataField][i].szi_ex27;
                        if(nameType){
                             if(szi_ex7==itemType&&szi_ex14==nameType){
                                index=i;
                                szi_ex27=szi_ex27_;
                            }
                        }else{
                             if(szi_ex7==itemType){
                                index=i;
                                szi_ex27=szi_ex27_;
                            }
                        }
                       
                    
                    }
                    if(index!=-1){
                        this.$delete(this.data[this.dataField],index)
                        //this.data[this.dataField].splice(index,1);
                        
                    }
                }else if(isFg){
                    let index=-1;
                    for(let i=0;i<this.data[this.dataField].length;i++){
                        let szi_ex1=this.data[this.dataField][i].szi_ex1;
                        let szi_ex27_=this.data[this.dataField][i].szi_ex27;
                        if(szi_ex1==name||szi_ex1==name2){
                            index=i;
                            szi_ex27=szi_ex27_;
                        }
                    }
                    if(index!=-1){
                        this.$delete(this.data[this.dataField],index)
                        //this.data[this.dataField].splice(index,1);
                        
                    }
                }
                row=JSON.parse(JSON.stringify(row))
                if(!row.szi_ex13)
                    row.szi_ex13=this.params;
                if(this.extype&&!row.szi_ex13){
                    row.szi_ex13=this.extype;
                }
                row.szi_ex14=nameType;
                if(data.num){
                    row.szi_ex4=data.num;
                }
                if(data.pri){
                    row.szi_ex2=data.pri;
                }
                if(data.amt){
                    row.szi_ex5=data.amt;
                }
                if(name2){
                    row.szi_ex1=name2;
                }
              
                row.szi_ex27=szi_ex27;
                this.$set(this.data[this.dataField], this.data[this.dataField].length , row); 
                this.setDataCheck();
            }
        },
        //添加服务项目的主方法
        addItem(data){
            console.log("addItems=================ff==============="+data)
            let datas=JSON.parse(data);
            let iscf=datas.iscf;
            let nameType="";
            if(datas.nameType){
                nameType=datas.nameType;
            }
           
            if(datas.addType=="string"){
                let itemType=datas.itemType;
                let name=datas.val;
                
                if(this.sfItemData.length==0){
                    this.$post(this.appid,this.postUrl,{gm_id:this.gm_id,depart:this.depart,dw:this.dw,type3:escape(this.extype)}).then(data=>{
                        this.sfItemData=[];
                        for(let i=0;i<data.item.length;i++){
                            this.sfItemData.push(data.item[i]);
                        }
                        
                        sessionStorage.setItem("sfItemData",JSON.stringify(this.sfItemData))
                        this.addItemDetail(name,itemType,datas.hour,datas.day,nameType,true,datas.isAdd);
                        if(data.isPriceSelect){
                            this.isPriceSelect=data.isPriceSelect;
                        }
                    
                    })
                }else{
                    this.addItemDetail(name,itemType,datas.hour,datas.day,nameType,true,datas.isAdd);
                }
                
            }else{
                try{
                    //不同的类型取不同的价格
                    if(datas.sf_ex77=="Y"){
                        this.$post("bygex","/byg/funeral/getFuneralSfItemByPrice",{sId:datas.szi_ex8,type:this.value}).then(data=>{
                            let price=data[0].price;
                            if(price){
                                datas.szi_ex2=price;
                                datas.szi_ex5=price;
                            }
                        });
                    }
                }catch(e){}
               
                if(!datas.szi_ex13){
                    if(this.extype){
                        datas.szi_ex13=this.extype;
                    }else{
                        datas.szi_ex13=this.params;
                    }
                }
                   
               
               if(this.extype&&!datas.szi_ex13){
                    datas.szi_ex13=this.extype;
                }
                let isOk=true;
                let sId="";
                let name="";
                if(datas.sf_ex24=="是"||datas.sf_ex24=="A"){
                    name=datas.szi_ex1;
                    sId=datas.szi_ex8
                }
                try{
                    console.log("cfCheck============================");
                    console.log(this.cfCheck)
                    if(this.cfCheck){
                        for(let i=0;i<this.cfCheck.length;i++){
                            let checks=this.cfCheck[i];
                            for(let j=0;j<this.data[this.dataField].length;j++){
                                let field=checks.field;
                                let val=checks.val;
                                let val_=this.data[this.dataField][j][field];
                                if(val==val_){
                                    let val_2=datas[field];
                                    if(val_==val_2){
                                        this.$alert(checks.msg);
                                        isOk=false;
                                        break;

                                    }
                                }
                            }
                        }
                    }
                }catch(e){}
                if(!isOk){
                    return;
                }
                if(iscf){
                    this.iscf=iscf;
                }
                if(this.iscf!='Y'){//去掉重复判断
                    //相同的项目增加数量
                    for(let i=0;i<this.data[this.dataField].length;i++){ 
                        let szi_ex1=this.data[this.dataField][i].szi_ex1;
                        let szi_ex8=this.data[this.dataField][i].szi_ex8;
                        let szi_ex4=this.data[this.dataField][i].szi_ex4;
                        let szi_ex2=this.data[this.dataField][i].szi_ex2;
                        let sf_ex24=this.data[this.dataField][i].sf_ex24;
                        let szi_ex16=this.data[this.dataField][i].szi_ex16;
                        let szi_ex31=this.data[this.dataField][i].szi_ex31;
                        console.log(szi_ex1+"=="+szi_ex31)
                        if(szi_ex31=="Y"){
                            continue;
                        }
                        if(szi_ex8==datas.szi_ex8){
                            szi_ex4++;
                            let data_=JSON.parse(JSON.stringify(this.data[this.dataField][i]));
                            data_.szi_ex4=szi_ex4;
                            data_.szi_ex5=szi_ex2*szi_ex4;
                            let isOks=true;
                            if(this.isCheckPrice=="Y"){
                                //判断价格是否一致，如果不一致则提示
                                if(datas.szi_ex2!=data_.szi_ex2){
                                    isOks=false;
                                    this.$confirm('该项目已存在，并且单价跟选择的单价不一致，是否新添加一个服务项目?', '提示', {
                                        confirmButtonText: '确定',
                                        cancelButtonText: '取消',
                                        type: 'warning'
                                        }).then(() => {
                                            this.$set(this.data[this.dataField],this.data[this.dataField].length,datas);
                                        }).catch(() => {
                                            this.$set(this.data[this.dataField], i , data_);       
                                     });
                                }
                            }
                           
                            if(this.isPriceSelect!="Y"&&isOks){//价格是下拉框，就是说服务项目里有子项目
                                this.$set(this.data[this.dataField], i , data_); 
                               
                            }
                            isOk=false;
                            break;
                        }
                        if((datas.sf_ex24=="是"||datas.sf_ex24=="A")&&szi_ex16!=""&&szi_ex16==name){
                            isOk=false;
                        }
                        
                    }
                }
                console.log("isOksss=============="+isOk)
               
                if(sId&&isOk){
                    //套餐本身也添加进去
                    if(datas.sf_ex24=="A"){
                        datas=this.changeDiscountPrice(datas);
                        datas.szi_ex31="A";
                        this.$set(this.data[this.dataField], this.data[this.dataField].length , datas);
                    }
                    this.$post("bygex",this.postUrlItem,{sId:sId}).then(data=>{
                       
                        if(data.length>0){
                            let cfItem=[]
                            for(let row_ of data){
                                try{
                                    row_.szi_ex13=this.params;
                                   if(this.extype&&!row_.szi_ex13){
                                        row_.szi_ex13=this.extype;
                                    }
                                    row_.szi_ex16=name;
                                    row_.szi_ex17=sId;
                                    if(datas.sf_ex24=="A"){
                                        row_.szi_ex31="Y"
                                        row_.isShow="N"
                                        row_.szi_ex32=sId;
                                    }
                                    let isCfs=false;
                                    //console.log("重复判断=============")
                                    //console.log(row_,"rows__________________________")
                                    if(row_.szi_ex31!='Y'){
                                        for(let i=0;i<this.data[this.dataField].length;i++){ 
                                            let szi_ex8=this.data[this.dataField][i].szi_ex8;
                                            if(szi_ex8==row_.szi_ex8&&row_.szi_ex31!='Y'){
                                                isCfs=true;
                                                let d={
                                                    row:this.data[this.dataField][i],
                                                    index:i
                                                }
                                                cfItem.push(d)
                                            }
                                        }
                                        
                                    }
                                    
                                    
                                    if(!isCfs){
                                        this.$set(this.data[this.dataField],this.data[this.dataField].length,row_);
                                        isChange=true;
                                    }
                                   
                                }catch(e){}
                               
                            }
                            if(cfItem.length>0){
                                  this.cfAlert(cfItem,0)     
                                
                            }

                            //this.changeAmt();
                        }
                    });
                }else if(isOk){
                    datas=this.changeDiscountPrice(datas);
                    this.$set(this.data[this.dataField], this.data[this.dataField].length , datas);
                    /*if(this.isPriceSelect=="Y"){//变更下拉框的值（价格）
                        this.loadSubItem(datas.szi_ex8,datas.szi_ex2);
                    }*/
                    
                    this.addRelItem(datas,datas.hour,datas.day,nameType); 
                }
             
            }
            
            this.setDataCheck()
        },
        cfAlert(cfItem,index){
            this.$confirm('服务项目【'+cfItem[index].row.szi_ex1+'】已存在，是否继续添加?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
                }).then(() => {
                        let row=cfItem[index].row
                        let szi_ex4=Number(row.szi_ex4)+1;
                        let szi_ex2=Number(row.szi_ex2);
                        
                        row.szi_ex4=szi_ex4;
                        row.szi_ex5=szi_ex2*szi_ex4;
                        if(this.isPriceSelect!="Y"){//价格是下拉框，就是说服务项目里有子项目
                            console.log(row,"rows===========")
                            console.log(cfItem[index].index,"rows===========1")
                            this.$set(this.data[this.dataField], cfItem[index].index , row); 
                            //isChange=true;
                        }
                        if(cfItem.length>index){
                            index++;
                            this.cfAlert(cfItem,index)
                        }
                        
                        
                }).catch(() => {
                    if(cfItem.length>index){
                        index++;
                        this.cfAlert(cfItem,index)
                    }     
            });
        },
        changeMenu(){
            let data={};
            for(let i=0;i<this.data[this.dataField].length;i++){
                let szi_ex31=this.data[this.dataField][i].szi_ex31;
                if(szi_ex31=="A"){
                    data[this.data[this.dataField][i].szi_ex8]=this.data[this.dataField][i].szi_ex4;
                }
            }
            for(let key in data){
                for(let i=0;i<this.data[this.dataField].length;i++){
                    let szi_ex31=this.data[this.dataField][i].szi_ex31
                    let szi_ex32=this.data[this.dataField][i].szi_ex32
                    if(szi_ex31=="Y"&&szi_ex32==key){
                        if(Number(data[key])<0){
                            if(Number(this.data[this.dataField][i].szi_ex4)>0){
                                this.data[this.dataField][i].szi_ex4="-"+ this.data[this.dataField][i].szi_ex4
                                this.data[this.dataField][i].szi_ex5=Number(this.data[this.dataField][i].szi_ex2)*Number(this.data[this.dataField][i].szi_ex4)
                            }
                        }
                        if(Number(data[key])>0){
                            if(Number(this.data[this.dataField][i].szi_ex4)<0){
                                this.data[this.dataField][i].szi_ex4=this.data[this.dataField][i].szi_ex4.replace("-","")
                                this.data[this.dataField][i].szi_ex5=Number(this.data[this.dataField][i].szi_ex2)*Number(this.data[this.dataField][i].szi_ex4)
                            }
                        }
                    }
                }
            }
        },
        //打折金额
        changeDiscountPrice(item){
            let sf_ex62=item.sf_ex62;
            if(sf_ex62=="折扣减免"){
                let szi_ex18=item.szi_ex18;//减免项目；
                let szi_ex2=Number(item.szi_ex2);
                let isOk=false;
                if(szi_ex18){
                    for(let i=0;i<this.data[this.dataField].length;i++){
                        let o=this.data[this.dataField][i];
                        let szi_ex7=o.szi_ex7;
                        let szi_ex1=o.szi_ex1;
                        let szi_ex2_=Number(o.szi_ex2);
                        if(szi_ex1==szi_ex18||szi_ex7==szi_ex18){
                            szi_ex2=-(1-szi_ex2)*szi_ex2_;
                            szi_ex2=szi_ex2.toFixed(1)
                            isOk=true;
                            break;
                        }
                    }
                    try{
                        if(!isOk){
                            for(let i=0;i<this.data["item2"].length;i++){
                                let o=this.data["item2"][i];
                                let szi_ex7=o.szi_ex7;
                                let szi_ex1=o.szi_ex1;
                                let szi_ex2_=Number(o.szi_ex2);
                                if(szi_ex1==szi_ex18||szi_ex7==szi_ex18){
                                    szi_ex2=-(1-szi_ex2)*szi_ex2_;
                                    szi_ex2=szi_ex2.toFixed(1)
                                    isOk=true;
                                    break;
                                }
                            }
                        }
                    }catch(e){}
                }
                item.szi_ex2=szi_ex2;
            }
            return item;

        },
        changeAmts(){
            this.changeAmt();
        },
        addRelItem(row,hour,day,nameType){//添加相搭配项目，并且有些搭配项目是要根据添加或者小时计算数量的，也要更新这些相关联项目的数量
            console.log("addRelItem======================");
            console.log(row)
            let sf_id=row.szi_ex8;
            console.log("hour==="+hour+"=="+day)
            //添加搭配项目
            this.$post(this.appid,this.postUrlDp,{sf_id:sf_id}).then(data=>{
              
                
                let szi_ex1_=row.szi_ex1;

                //反向，这个主要是用于添加相搭配项目的时候，找到主项目，并且获取主项目的数量和金额赋值
                //因为这个方法在添加主项目和相关联项目时都会调用
                //比如主服务项目（礼厅）先添加完成，然后找到礼厅相关联的项目szi_ex19,因为礼厅是主项目所有这个字段为空，下面for获取不到row_,就不存在要该礼厅的数量和金额
                //但主项目（礼厅）添加完后，会从后台获取到data.name（在下面）然后添加子项目（冰柜）。子项目添加完成后，又进入该方法，冰柜的szi_ex19值就是相对应的礼厅名称
                //然后就可以反向获取上一步添加好的礼厅的数量，然后冰柜根据获取的数量重新计算金额，赋值给冰柜
                let row_=null;
                for(let i=0;i<this.data[this.dataField].length;i++){
                    let item=this.data[this.dataField][i];
                    let szi_ex2=Number(item.szi_ex2);
                    let szi_ex1=item.szi_ex1;
                    let szi_ex19=item.szi_ex19;
                    let szi_ex31=item.szi_ex31;
                    if(szi_ex31=="Y")
                        continue;
                    if((","+szi_ex19+",").indexOf(","+szi_ex1_+",")!=-1){
                        row_=item;
                    }
                }
                console.log(row_,"rows______________________________________________________")
                if(row_){
                    let szi_ex4_=Number(row_.szi_ex4);
                    let szi_ex5_=row_.szi_ex5;
                    let szi_ex2=Number(row.szi_ex2);
                    row.szi_ex4=szi_ex4_;
                    row.szi_ex5=szi_ex2*szi_ex4_;
                    if(nameType)
                    row.szi_ex14=nameType;
                    if(this.extype&&!row.szi_ex13){
                        row.szi_ex13=this.extype;
                    }
                    //这里其实就是修改刚刚添加的服务项目的数量和金额
                    this.$set(this.data[this.dataField], this.data[this.dataField].length-1 , row); 
                }
                //添加相关联的服务项目
                if(data.name){
                    let names=data.name.split(",");
                    for(let i=0;i<names.length;i++){
                        let n=names[i];
                        //该方法后面还会在调用本方法
                        this.addItemDetail(n,"",hour,day,nameType);
                        
                    }
                }
                //找到相关联项目，这个主要是修改相关联项目的数量（根据天数和小时，比如礼厅相关联的项目，冰柜）
                if(data.name2){
                    let names2=data.name2.split(",");
                    
                    for(let h=0;h<names2.length;h++){
                        let n=names2[h];
                        let isSave=false;
                        for(let i=0;i<this.data[this.dataField].length;i++){
                            let item=this.data[this.dataField][i];
                            let szi_ex2=Number(item.szi_ex2);
                            let szi_ex1=item.szi_ex1;
                            let szi_ex4=Number(item.szi_ex4);
                            let szi_ex3=item.szi_ex3;
                            let szi_ex31=item.szi_ex31;
                            let szi_ex5=Number(item.szi_ex5);
                            if(szi_ex31=="Y")
                                continue;
                            let szi_ex5_=0;
                            if(szi_ex1==n){
                                if(szi_ex3.indexOf("时")!=-1){
                                    if(hour){
                                        szi_ex5_=hour*szi_ex2;
                                        item.szi_ex4=hour;
                                        isSave=true;
                                    }
                                    
                                    
                                }else{
                                    if(day){
                                        szi_ex5_=day*szi_ex2;
                                        item.szi_ex4=day;
                                        isSave=true;
                                    }
                                    
                                }
                                if(szi_ex3.indexOf("场")==-1&&szi_ex3.indexOf("次")==-1){
                                    if(szi_ex5!=szi_ex5_&&isSave){
                                        item.szi_ex5=szi_ex5_;
                                        this.$set(this.data[this.dataField], i , item); 
                                            
                                    }
                                }
                                
                            }
                        }
                    }

                    
                }

               // this.setJm();
                //this.changeAmt();
            })
        },
        //根据名字来添加;isAdd等于Y；代表项目在也添加
        addItemDetail(name,itemType,hour,day,nameType,hasXH,isAdd){
             let row=null;
             console.log("name==="+name+"=="+itemType)
             
             for(let i=0;i<this.sfItemData.length;i++){
                let szi_ex1=this.sfItemData[i].szi_ex1;
                let szi_ex7=this.sfItemData[i].szi_ex7;
                
                if(itemType){
                    
                    if(szi_ex1==name&&itemType==szi_ex7){
                        row=this.sfItemData[i];
                    }
                    
                }else{
                    if(szi_ex1==name){
                        row=this.sfItemData[i];
                    }
                }
                
            }
            let isOk=true;
             let szi_ex27="";
             console.log("itemType======"+itemType+"=="+nameType)

             let itemIndex=-1;
           //  console.log(this.sfItemData)
           //  console.log(JSON.stringify(row))
             if(row!=null){
                for(let i=0;i<this.data[this.dataField].length;i++){
                    let szi_ex1=this.data[this.dataField][i].szi_ex1;
                    let szi_ex7=this.data[this.dataField][i].szi_ex7;
                    let szi_ex14=this.data[this.dataField][i].szi_ex14;
                    let szi_ex31=this.data[this.dataField][i].szi_ex31;
                    if(szi_ex31=="Y")
                        continue;
                    if(itemType){
                        if(nameType){
                            if(szi_ex1==row.szi_ex1&&itemType==szi_ex7&&szi_ex14==nameType){
                                isOk=false;
                                itemIndex=i;
                            }
                        }else{
                            if(szi_ex1==row.szi_ex1&&itemType==szi_ex7){
                                isOk=false;
                                itemIndex=i;
                            }
                        }
                       
                    }else{
                        if(nameType){
                            if(szi_ex1==row.szi_ex1&&szi_ex14==nameType){
                                isOk=false;
                                itemIndex=i;
                            }
                        }else{
                            if(szi_ex1==row.szi_ex1){
                                isOk=false;
                                itemIndex=i;
                            }
                        }
                        
                    }
                    
                }
            
            }
            
            console.log("addItemsss=s======="+"="+name+"="+isOk+"=="+this.data["item"].length+"==isAdd:"+isAdd+"=="+itemIndex);
            console.log(row)
            if(row!=null&&isOk){
                row=JSON.parse(JSON.stringify(row))
                if(itemType){
                    console.log("itemType============"+itemType)
                    let index=-1;
                    let isXH=true;
                    //删除礼厅相关的所有项目，需要循环
                    while(isXH){
                        console.log(this.data[this.dataField],"DATAfIELD============")
                        for(let i=0;i<this.data[this.dataField].length;i++){
                            let szi_ex7=this.data[this.dataField][i].szi_ex7;
                            let szi_ex14=this.data[this.dataField][i].szi_ex14;
                            let szi_ex27_=this.data[this.dataField][i].szi_ex27;
                            let szi_ex31_=this.data[this.dataField][i].szi_ex31;
                            if(szi_ex31_=="Y")
                                continue;
                            if(nameType){
                                if(itemType=="告别厅"){
                                    if(szi_ex7==itemType||nameType==szi_ex14){
                                        index=i;
                                        
                                    }
                                    if(szi_ex7==itemType&&nameType==szi_ex14){
                                        szi_ex27=szi_ex27_;
                                    }
                                    
                                }else if(szi_ex7==itemType&&nameType==szi_ex14){
                                    index=i;
                                    szi_ex27=szi_ex27_;
                                }
                            }else{
                                if(szi_ex7==itemType){
                                    index=i;
                                    szi_ex27=szi_ex27_;
                                }
                            }
                            
                        
                        }
                        if(index!=-1){
                            this.$delete(this.data[this.dataField],index)
                            index=-1;
                            //this.data[this.dataField].splice(index,1);
                           
                        }else{
                            isXH=false;
                        }
                        if(!hasXH){
                            isXH=false;
                        }
                    }
                    
                }
                if(!row.szi_ex13)
                    row.szi_ex13=this.params;
               if(this.extype&&!row.szi_ex13){
                    row.szi_ex13=this.extype;
                }
                let szi_ex3=row.szi_ex3;
                let sf_ex51=row.szi_ex28
                let num=1;
                let szi_ex2=Number(row.szi_ex2);
               
                if(hour&&szi_ex3.indexOf("时")!=-1){
                    num=hour;
                    let szi_ex5=num*szi_ex2;
                    row.szi_ex5=szi_ex5;
                    row.szi_ex4=num;
                }else if(day&&szi_ex3.indexOf("天")!=-1){
                    if(sf_ex51=="自然天数"){
                        day=Number(day)+1;
                    }
                    day=Number(day)==0 ? 1:day;
                    num=day;
                    let szi_ex5=num*szi_ex2;
                    row.szi_ex5=szi_ex5;
                    row.szi_ex4=num;
                    
                }
                row.szi_ex27=szi_ex27;
                row.szi_ex14=nameType;
                row=this.changeDiscountPrice(row);//折扣减免

               
               
                this.$set(this.data[this.dataField], this.data[this.dataField].length , row); 
              
                this.addRelItem(row,hour,day,nameType)


            }else if(isAdd=="Y"&&itemIndex!=-1){
               
                let itemRow=this.data[this.dataField][itemIndex];
                let szi_ex3=itemRow.szi_ex3;
                let sf_ex51=itemRow.szi_ex28
                let num=1;
                let szi_ex2=Number(itemRow.szi_ex2);
               
                if(hour&&szi_ex3.indexOf("时")!=-1){
                    num=hour;
                    let szi_ex5=num*szi_ex2;
                    itemRow.szi_ex5=szi_ex5;
                    itemRow.szi_ex4=num;
                }else if(day&&szi_ex3.indexOf("天")!=-1){
                    if(sf_ex51=="自然天数"){
                        day=Number(day)+1;
                    }
                    day=Number(day)==0 ? 1:day;
                    num=day;
                    let szi_ex5=num*szi_ex2;
                    itemRow.szi_ex5=szi_ex5;
                    itemRow.szi_ex4=num;
                    
                }else{
                    day=Number(day)==0 ? 1:day;
                    num=day;
                    let szi_ex5=num*szi_ex2;
                    itemRow.szi_ex5=szi_ex5;
                    itemRow.szi_ex4=num;
                }

                this.$set(this.data[this.dataField], itemIndex , itemRow); 
            }else if(row==null){
                if(itemType){
                    console.log("itemType============"+itemType)
                    let index=-1;
                    let isXH=true;
                    //删除礼厅相关的所有项目，需要循环
                    while(isXH){
                        console.log(this.data[this.dataField],"DATAfIELD============")
                        for(let i=0;i<this.data[this.dataField].length;i++){
                            let szi_ex7=this.data[this.dataField][i].szi_ex7;
                            let szi_ex14=this.data[this.dataField][i].szi_ex14;
                            let szi_ex27_=this.data[this.dataField][i].szi_ex27;
                            let szi_ex31_=this.data[this.dataField][i].szi_ex31;
                            if(szi_ex31_=="Y")
                                continue;
                            if(nameType){
                                if(itemType=="告别厅"){
                                    if(szi_ex7==itemType||nameType==szi_ex14){
                                        index=i;
                                        
                                    }
                                    
                                }else if(szi_ex7==itemType&&nameType==szi_ex14){
                                    index=i;
                                }
                            }else{
                                if(szi_ex7==itemType){
                                    index=i;
                                }
                            }
                            
                        
                        }
                        if(index!=-1){
                            this.$delete(this.data[this.dataField],index)
                            index=-1;
                            //this.data[this.dataField].splice(index,1);
                           
                        }else{
                            isXH=false;
                        }
                        if(!hasXH){
                            isXH=false;
                        }
                    }
                    
                }
            }
            this.setDataCheck();
        },
        changeInput(data){
            
          //  this.$emit("input",data);
            let datas=JSON.parse(data);
           
            if(datas.type!="add")
                this.setJm();
            this.changeAmt();
        },
        
        isRealNum(val){
            // isNaN()函数 把空串 空格 以及NUll 按照0来处理 所以先去除，
            　　if(val === "" || val ==null){
                    return false;
            　　}
            if(!isNaN(val)){　　　　
                　　//对于空数组和只有一个数值成员的数组或全是数字组成的字符串，
                　　//isNaN返回false，例如：'123'、[]、[2]、['123'],isNaN返回false,
                //所以如果不需要val包含这些特殊情况，则这个判断改写为if(!isNaN(val) && typeof val === 'number' )
                　　　 return true; 
            }else{ 
            　　return false; 
            } 

        },
        changeAmt(){
            
            let amt=0;
            let amt_total=0;
            let amt_jm=0;
            let amt_yh=0;
            let gs_total=0;
            let gl_total=0;
            this.change=false;
            let amt_bz=0;//补助金额（目前就昆明西郊）

            let indexss=1;
            for(let i=0;i<this.data[this.dataField].length;i++){
                let item=this.data[this.dataField][i];
                if(item.szi_ex31=="Y"||item.isShow=='N'){
                    continue;
                }
                if(item.isshow!='N'){
                   // if(this.data[this.dataField][i].No){
                        let indexsss=Number(this.data[this.dataField][i].No);
                       
                        if(indexsss!=indexss){

                            this.$set(this.data[this.dataField][i],"No",indexss)
                            this.change=true;
                        }
                        indexss++;
                   // }
                    
                }
                if(!this.isRealNum(item.szi_ex27)){
                    item.szi_ex27="";
                }
                let szi_ex2=Number(item.szi_ex2);
                let szi_ex4=Number(item.szi_ex4);
                let szi_ex27=item.szi_ex27;
                let szi_ex5=szi_ex2*szi_ex4;
                let szi_ex5_=item.szi_ex5;
                let szi_ex7_=item.szi_ex7;
                let szi_ex38=item.szi_ex38;
                if(szi_ex5!=szi_ex5_&&(""+szi_ex5)!="NaN"&&(""+szi_ex5_)!="NaN"){//如果总金额不一样了，才重新赋值
                     item.szi_ex5=szi_ex5;
                     this.$set(this.data[this.dataField], i , item); 
                     this.change=true;
                }
               
                
                if(szi_ex5<0)
                    amt_jm+=szi_ex5;
                
                else
                    amt_total+=szi_ex5;
                
                if(szi_ex7_.indexOf("补助")!=-1){//昆明西郊
                    amt_bz+=szi_ex5;
                }else{
                    amt+=szi_ex5;
                }
                if(szi_ex27){
                    szi_ex27=Number(szi_ex27);
                    amt-=szi_ex27;
                    amt_yh+=szi_ex27;
                }

                if(szi_ex38=='N'){
                    gl_total+=szi_ex5;
                }else{
                    gs_total+=szi_ex5;
                }
               
            }
            if(this.sz_ex61s){
                amt=amt-Number(this.sz_ex61s);
                amt_yh=amt_yh+Number(this.sz_ex61s)
            }
            if(this.c_ex60){
                amt=amt-Number(this.c_ex60);
                amt_yh=amt_yh+Number(this.c_ex60)
            }
            try{
                if(this.data.szInfo.sz_ex135=="Y"){
                    amt_jm=amt_total;
                    amt=0;
                }
            }catch(e){}
            
           


            this.amt_totals=amt_total;
            this.jm_totals=-amt_jm;
            this.gl_totals=gl_total;
            this.gs_totals=gs_total;
            this.bz_totals=amt_bz;
            this.sh_totals=amt;
            this.yh_totals=amt_yh;
            if(!this.decimal){
                this.decimal="2"
            }
            try{
                if(this.decimal!=undefined&&this.decimal!="undefined"&&this.decimal){
                    if(this.amt_totals)
                        this.amt_totals=Number(this.amt_totals).toFixed(this.decimal)
                    if(this.jm_totals)
                        this.jm_totals=Number(this.jm_totals).toFixed(this.decimal)
                    if(this.gl_totals)
                        this.gl_totals=Number(this.gl_totals).toFixed(this.decimal)
                    if(this.bz_totals)
                        this.bz_totals=Number(this.bz_totals).toFixed(this.decimal)
                    if(this.sh_totals)
                        this.sh_totals=Number(this.sh_totals).toFixed(this.decimal)
                    
                    if(this.yh_totals)
                        this.yh_totals=Number(this.yh_totals).toFixed(this.decimal)
                }
            }catch(e){}

            try{
                if(this.isgm=='Y'){
                    let c_ex57=this.data["gmInfo"].c_ex57;
                     if(c_ex57==""||c_ex57=="N"){
                          this.data["gmInfo"].c_ex59=amt_total;
                            this.data["gmInfo"].c_ex61=amt;
                     }
                   
                }
            }catch(e){}
            if(this.bz_totals){
                this.shTitle="自费金额";
            }
            if(this.firstTotal=="Y"){
                this.yh_totalsOld=this.yh_totals;
                this.firstTotal="N";
            }
            if(this.yh_totals!=this.yh_totalsOld&&amt_yh){
                try{
                    this.data["szInfo"].sz_ex59="待审核";
                    this.data["szInfo"].sz_dat12=this.getNowDate();

                    this.data["commonAuth"]={
                        ca_ex6:"待审核",
                        ca_dat1:this.getNowDate()
                    };
                }catch(e){}
                 try{
                    this.data["gmInfo"].c_ex62="待审核";
                    this.data["commonAuth"]=[{
                        ca_ex3:"公墓优惠审批",
                        ca_ex6:"待审核",
                        ca_ex9:amt_total,
                        ca_ex10:amt_yh,
                        ca_ex12:amt,
                        ca_ex14:"单个公墓",
                        ca_ex15:this.data["gmInfo"].address+"("+this.data["gmInfo"].c_ex10+"元)",
                        ca_dat1:this.getNowDate()
                    }];
                  
                }catch(e){}
            }
            if(!amt_yh){
                try{
                    this.data["commonAuth"]=[];
                    this.data["gmInfo"].c_ex62="";
                }catch(e){}
            }
            this.changeMenu();
            
            try{
                this.$refs.selectshow.initLoad();
            }catch(e){}
            this.replaceXMS();
        },
        getDaysBetween(dateString1,dateString2){
            var  startDate = Date.parse(dateString1);
            var  endDate = Date.parse(dateString2);
            var days=(endDate - startDate)/(1*24*60*60*1000);
            // alert(days);
            return  days;
        },
        getDaysBetweenHour(dateString1,dateString2){
            var  startDate = Date.parse(dateString1);
            var  endDate = Date.parse(dateString2);
            var days=(endDate - startDate)/(1*60*60*1000);
            // alert(days);
            return  days;
        },
        loadFirst(){
            
            for(let i=0;i<this.sfItemData.length;i++){
                if(this.sfItemData[i].sf_ex33=='Y'){
                    let isOk=true;
                    let row=this.sfItemData[i];
                    let szi_ex8=this.sfItemData[i].szi_ex8;
                    for(let i=0;i<this.data[this.dataField].length;i++){
                        if(this.data[this.dataField][i].szi_ex8==szi_ex8){
                           isOk=false;
                        }
                    }
                    console.log("sf_ex33===="+row.szi_ex1)
                    if(isOk){
                         this.$set(this.data[this.dataField],this.data[this.dataField].length,row);
                    }
                }
            }
           
        },
        loadCar(carNum){
            let row=null;
            let rIndex=-1;
            let isOk=true;
            let carNum_=0;
            for(let i=0;i<this.sfItemData.length;i++){
                if(this.sfItemData[i].szi_ex1=='停车费'){
                    row=this.sfItemData[i];
                }
            }
            for(let i=0;i<this.data[this.dataField].length;i++){
                if(this.data[this.dataField][i].szi_ex1=='停车费'){
                    rIndex=i;
                    carNum_=this.data[this.dataField][i].szi_ex4;
                }
            }
            if(carNum_==carNum){
                isOk=false;
            }
         
           if(row&&isOk){
               row.szi_ex4=carNum;
               let szi_ex2=Number(row.szi_ex2);
               row.szi_ex5=szi_ex2*Number(carNum)
               row.szi_ex13="业务";
             
               if(this.extype&&!row.szi_ex13){
                    row.szi_ex13=this.extype;
                }
               this.$set(this.data[this.dataField],this.data[this.dataField].length,row);
               //this.$refs.tableEditss.addItem(JSON.stringify(row));
            }
            if(rIndex>=0){
                this.$delete(this.data[this.dataField],rIndex)
                //this.tableData.splice(rIndex,1);
            }
        },
         loadMeal(sId){
            
              return new Promise((resolve,reject) => {
               
                this.$postAsync("bygex",this.postUrlItem,{sId:sId}).then(data=>{
                    resolve(data);
                });
              });
             
           
           
        },
        loadFn(hy_ex6){
           // this.isFnjmAge=16
           console.log("hy_ex6===="+hy_ex6+"=="+this.hy_ex6)
           try{
                if(hy_ex6!=this.hy_ex6){
                    let rIndex=-1
                    let row=null;
    
                    let sId="";
                    for(let i=0;i<this.sfItemData.length;i++){
                        
                        if(this.sfItemData[i].szi_ex9==hy_ex6){
                           
                            if(this.sfItemData[i].sf_ex24!="是"&&this.sfItemData[i].sf_ex24!="A"){//不是套餐
                                row=this.sfItemData[i];
                            }else{
                                sId=this.sfItemData[i].szi_ex8;
                                
                            }
                        }
                       
                    }
                    let isOk=true;
                    let delItem=[];
                    this.replaceUserObj={};
                    let addItem_=[]
                    let addObj={}
                    for(let i=0;i<this.data[this.dataField].length;i++){
                         if(this.data[this.dataField][i].szi_ex15&&this.data[this.dataField][i].szi_ex15.indexOf(hy_ex6)!=-1){
                               isOk=false;
                         }
                         console.log("delItem===="+this.data[this.dataField][i].szi_ex15+"="+this.data[this.dataField][i].szi_ex1+"=="+i+"=="+this.data[this.dataField].length)
                        // console.log("dataField======================"+this.data[this.dataField][i].szi_ex16+"=="+this.data[this.dataField][i].szi_ex9)
                         if(this.data[this.dataField][i].szi_ex16=="火化炉"&&this.data[this.dataField][i].szi_ex15!=''&&(this.data[this.dataField][i].szi_ex15.indexOf(hy_ex6)==-1)){
                             delItem.push(this.data[this.dataField][i].szi_ex8)
                             if(this.data[this.dataField][i].szi_ex1=="遗体接运（高档车）"){//昆明西郊，切换运费的时候，公里数必须记录
                                  this.kmtsxm=this.data[this.dataField][i].szi_ex2;
                             }
                             if(this.replaceUser&&this.replaceUser[this.data[this.dataField][i].szi_ex1]){//目前昆明西郊使用
                                let fields=this.replaceUser[this.data[this.dataField][i].szi_ex1].split(",");
                                for(let hhh=0;hhh<fields.length;hhh++){
                                    this.replaceUserObj[fields[hhh]]=JSON.parse(JSON.stringify(this.data[this.dataField][i]))
                                }
                             }
                             if(this.replaceXM2&&this.replaceXM2[this.data[this.dataField][i].szi_ex1]){
                                addItem_.push(this.replaceXM2[this.data[this.dataField][i].szi_ex1])
                                addObj[this.replaceXM2[this.data[this.dataField][i].szi_ex1]]=JSON.parse(JSON.stringify(this.data[this.dataField][i]))
                             }
                             
                         }
                         console.log("11111111111111111111111111111111111")
                        
                    }
                    let isChange=false;
                    console.log(addItem_,"addItem_============")
                    console.log(delItem)
                    console.log("isOk===s=========="+isOk);
                    if(isOk){
                        if(delItem.length>0){
                            
                            console.log("delItem删除-------------------------")    
                            for(let id of delItem){
                                let index=-1;
                                for(let i=0;i<this.data[this.dataField].length;i++){
    
                                    if(this.data[this.dataField][i].szi_ex8==id){
                                        index=i;
                                        break;
                                    }
                                }
                                if(index>=0){
                                    this.$delete(this.data[this.dataField],index)
                                }
                            }
                            
                        }
                        if(addItem_.length>0){
                            addItem_.forEach(name=>{
                                console.log("NAME============"+name+"="+this.sfItemData.length)
                                this.sfItemData.forEach((item,index)=>{
                                    if(item.szi_ex1==name){
                                        let d_=JSON.parse(JSON.stringify(item));
                                        let dold=addObj[name];
                                        if(dold.szi_ex51){
                                            d_["szi_ex51"]=dold.szi_ex51;
                                            d_["szi_ex52"]=dold.szi_ex52;
                                            d_["szi_ex53"]=dold.szi_ex53;
                                        }
                                        console.log(d_,"d_======================================================")
                                        this.$set(this.data[this.dataField],this.data[this.dataField].length,d_)
                                    }
                                })
                            })
                        }
                        if(sId){
                            this.$post("bygex",this.postUrlItem,{sId:sId}).then(data=>{
                                if(data.length>0){
                                    for(let row_ of data){
                                        let szi_ex8__=row_.szi_ex8;
                                        let isSave=true;
                                        for(let i=0;i<this.data[this.dataField].length;i++){
                                            if(szi_ex8__==this.data[this.dataField][i].szi_ex8){
                                                isSave=false;
                                            }
                                        }
                                        console.log("mealItem=="+row_.szi_ex1+"=="+isSave)
                                        if(isSave){
                                            row_.szi_ex13="业务";
                                            row_.szi_ex15=hy_ex6;
                                            row_.szi_ex16="火化炉";

                                            if(row_.szi_ex1=="遗体接运（高档车）"&&this.kmtsxm){
                                                row_.szi_ex2=this.kmtsxm;
                                                row_.szi_ex5=this.kmtsxm;
                                            }
                                            if(this.replaceUserObj&&this.replaceUserObj[row_.szi_ex1]){
                                                let szi_ex51=this.replaceUserObj[row_.szi_ex1].szi_ex51;
                                                let szi_ex52=this.replaceUserObj[row_.szi_ex1].szi_ex52;
                                                let szi_ex53=this.replaceUserObj[row_.szi_ex1].szi_ex53;

                                                if(szi_ex51){
                                                    row_.szi_ex51=szi_ex51;
                                                    row_.szi_ex52=szi_ex52;
                                                    row_.szi_ex53=szi_ex53;
                                                }
                                            }
                                            this.$set(this.data[this.dataField],this.data[this.dataField].length,row_);
                                            isChange=true;
                                        }
                                        
                                    }
                                    //this.changeAmt();
                                }
                            });
                        }
                       // console.log(row,"row--------s----s--s-s-s-s-s--")
                        if(row){
                            row.szi_ex13="业务";
                            row.szi_ex15=hy_ex6;
                            row.szi_ex16="火化炉";
                            if(this.isFnjm&&this.isFnjmAge){
                                try{
                                    if(this.data["szInfo"].sz_ex5){
                                        if(Number(this.data["szInfo"].sz_ex5)<=Number(this.isFnjmAge)){
                                            let szi_ex2=row.sf_ex9;
                                            szi_ex2=Number(szi_ex2)/2;
                                            row.szi_ex2=szi_ex2;
                                            row.szi_ex5=szi_ex2;
                                        }
                                    }
                                }catch(e){}
                            }
                            console.log("loadFn==========")
                            this.$set(this.data[this.dataField],this.data[this.dataField].length,row);
                            isChange=true;
                            this.addRelItem(row,1,1); 
                            
                        }
                        
    
                    }
                    
                
                    if(isChange){
                       // this.setJm();
                       // this.changeAmt();
                       
                    }
                    this.hy_ex6=hy_ex6;
                }
           }catch(e){}
            
            
        },
        loadSubItem(sf_id,amt){
            this.$post(this.appid,"/byg/funeral/getSubItem",{sf_id:sf_id}).then(data=>{
                let options=[];
                let isOk=false;
                for(let i=0;i<data.length;i++){
                    let d=data[i];
                    d.optname=d.ssf_ex2;
                    d.optvalue=d.ssf_ex2;
                    options.push(d);

                    try{
                        if(Number(amt)==Number(d.ssf_ex2)){
                            isOk=true;
                        }
                    }catch(e){}
                }
                
                if(!isOk){
                    let d={};
                    d.optname=amt;
                    d.optvalue=amt;
                    options.push(d)
                }
                
                this.$refs.tableEditss.setDataSource(this.data[this.dataField].length-1,options)
            });
        },
        dingjin(){
            try{
                if(this.data.gmInfo.c_ex52){
                    

                    let isOk=true;
                    for(let i=0;i<this.data[this.dataField].length;i++){
                        let szi_ex7=this.data[this.dataField][i].szi_ex7;
                        if(szi_ex7=="定金"){
                            isOk=false;
                        }
                    }
                    if(isOk){
                        if(this.sfItemData.length==0){
                            this.$post(this.appid,this.postUrl,{gm_id:this.gm_id,depart:this.depart,dw:this.dw,type3:escape(this.extype)}).then(data=>{
                                this.sfItemData=[];
                                for(let i=0;i<data.item.length;i++){
                                    this.sfItemData.push(data.item[i]);
                                }
                                let isOkss=true;
                                for(let i=0;i<this.data[this.dataField].length;i++){
                                    let szi_ex7=this.data[this.dataField][i].szi_ex7;
                                    if(szi_ex7=="定金"){
                                        isOkss=false;
                                    }
                                }
                                if(isOkss){
                                     let item=null;
                                    for(let i=0;i<this.sfItemData.length;i++){
                                        let szi_ex7=this.sfItemData[i].szi_ex7;
                                        if(szi_ex7=="定金"){
                                            item=JSON.parse(JSON.stringify(this.sfItemData[i]));
                                        }
                                    }
                                    if(item){
                                        item.szi_ex2="-"+this.data.gmInfo.c_ex52;
                                        item.szi_ex5="-"+this.data.gmInfo.c_ex52;
                                         this.$set(this.data[this.dataField],this.data[this.dataField].length,item);
                                    }
                                }
                               
                                if(data.isPriceSelect){
                                    this.isPriceSelect=data.isPriceSelect;
                                }
                                
                            })
                        }else{
                            let item=null;
                            for(let i=0;i<this.sfItemData.length;i++){
                                let szi_ex7=this.sfItemData[i].szi_ex7;
                                if(szi_ex7=="定金"){
                                    item=JSON.parse(JSON.stringify(this.sfItemData[i]));
                                }
                            }

                            if(item){
                                item.szi_ex2="-"+this.data.gmInfo.c_ex52;
                                item.szi_ex5="-"+this.data.gmInfo.c_ex52;
                                this.$set(this.data[this.dataField],this.data[this.dataField].length,item);
                            }
                        }
                    }
                }
            }catch(e){}
        },
        //管理费
        loadGlf(){
            //alert(this.isgm)
            if(this.isgm=="Y"){
                this.$post("business","/api/common/readCommonSet",{id:"管理费设置"}).then(data=>{
                    let set1=data.set1;
                    let set2=data.set2;
                   // alert(set1)
                    if(set1=="初次购买需要收取"){
                        let c_ex4=this.data["gmInfo"].c_ex4;
                        let c_ex27=this.data["gmInfo"].c_ex27;
                        
                        let gmlType=sessionStorage.getItem("管理费单位")
                        if(c_ex4&&c_ex27!='Y'){
                            let row=null;
                            let row_bak=null;
                            let isAdd=true;
                            let isYG=true;
                            for(let i=0;i<this.sfItemData.length;i++){
                                let szi_ex7=this.sfItemData[i].szi_ex7;
                                let szi_ex3=this.sfItemData[i].szi_ex3;
                                if(szi_ex7=="管理费"){
                                    row=this.sfItemData[i];
                                  
                                }
                               /* if(szi_ex7=="管理费"&&szi_ex3==gmlType){
                                    row=this.sfItemData[i];
                                  
                                    row_bak=this.sfItemData[i];
                                }*/
                            }
                            if(!row&&row_bak){
                                row=row_bak;
                                isYG=false;
                            }
                            for(let i=0;i<this.data["item"].length;i++){
                                let szi_ex7=this.data["item"][i].szi_ex7;
                                let szi_ex3=this.sfItemData[i].szi_ex3;
                                /*if(szi_ex7=="管理费"&&!isYG){
                                    isAdd=false;
                                }else if(szi_ex7=="管理费"&&szi_ex3==gmlType){
                                    isAdd=false;
                                }*/
                                if(szi_ex7=="管理费"){
                                    isAdd=false;
                                }
                            }
                            console.log(row,"rows============================="+gmlType);
                            console.log(row_bak,"rows=============================");
                            if(row&&isAdd){
                                 
                                let gm_dat3=this.data["gmInfo"].gm_dat3;
                                let gm_dat4=this.data["gmInfo"].gm_dat4;
                                console.log("gm_dat3-gm_dat4========="+gm_dat3+"="+gm_dat4)
                                if(gm_dat3&&gm_dat4){
                                     let years=this.getDateYearSub(gm_dat3,gm_dat4);
                                    let months=this.getDateMonthSub(gm_dat3,gm_dat4);
                                    if(row.szi_ex3.indexOf("月")!=-1){
                                        years=months;
                                    }
                                    set2=years;
                                    
                                console.log("set2222================"+set2)
                                }

                                
                                let set2_=Number(set2);
                                console.log("set2================"+set2)
                                if(set2_){
                                    row.szi_ex2=c_ex4;
                                    row.szi_ex4=set2;
                                    row.szi_ex5=set2_*Number(c_ex4);
                                    try{
                                        this.data["gmInfo"].c_ex58=row.szi_ex5;
                                      
                                    }catch(e){}
                                    this.$set(this.data["item"],this.data["item"].length,row);
                                }
                               
                            }
                            this.isSetGlf="Y"
                        }
                        
                    }
                })
                
            }
        },
            //startDateStr(2017-02-22) endDateStr(2018-02-21)
        getDateYearSub(startDateStr, endDateStr) {
            var day = 24 * 60 * 60 *1000; 

            var sDate = new Date(Date.parse(startDateStr.replace(/-/g, "/")));
            var eDate = new Date(Date.parse(endDateStr.replace(/-/g, "/")));

            //得到前一天(算头不算尾)
           // sDate = new Date(sDate.getTime() - day);

            //获得各自的年、月、日
            var sY  = sDate.getFullYear();     
            var sM  = sDate.getMonth()+1;
            var sD  = sDate.getDate();
            var eY  = eDate.getFullYear();
            var eM  = eDate.getMonth()+1;
            var eD  = eDate.getDate();
            if(eY > sY ) {
                return eY - sY;
            } else {
              //  alert("两个日期之间并非整年，请重新选择");
                return 0;
            }
        },
        getDateMonthSub(startDateStr, endDateStr) {
            var day = 24 * 60 * 60 *1000; 

            var sDate = new Date(Date.parse(startDateStr.replace(/-/g, "/")));
            var eDate = new Date(Date.parse(endDateStr.replace(/-/g, "/")));

            //得到前一天(算头不算尾)
           // sDate = new Date(sDate.getTime() - day);

            //获得各自的年、月、日
            var sY  = sDate.getFullYear();     
            var sM  = sDate.getMonth()+1;
            var sD  = sDate.getDate();
            var eY  = eDate.getFullYear();
            var eM  = eDate.getMonth()+1;
            var eD  = eDate.getDate();
            let month=(eY*12+eM)-(sY*12+sM);
            return month;
        },
        getNowDate(){
            var mydate=new Date();
            var mymonth=mydate.getMonth()+1;
            var myday= mydate.getDate();
            var year= mydate.getFullYear();
            if(mymonth<10)
                mymonth="0"+mymonth;
            if(myday<10)
                myday="0"+myday;
            var date = year+"-"+mymonth+"-"+myday
            return date;
        },
        openSelect(){
            try {
                if(this.exkey.departField&&!this.depart){
                    alert("请先选择所属馆")
                    return;
                }
            } catch (error) {
                
            }
            
            if(this.isYtj!='Y'&&!this.isDialog)
                this.drawer=true;
            else
                this.outerVisible=true;
            this.$refs.selectshow.initLoad();
        },
        getNowDate(){
            var date = new Date();
            var sign2 = ":";
            var year = date.getFullYear() // 年
            var month = date.getMonth() + 1; // 月
            var day = date.getDate(); // 日
            var hour = date.getHours(); // 时
            var minutes = date.getMinutes(); // 分
            var seconds = date.getSeconds() //秒
            var weekArr = ['星期一', '星期二', '星期三', '星期四', '星期五', '星期六', '星期天'];
            var week = weekArr[date.getDay()];
            // 给一位数的数据前面加 “0”
            if (month >= 1 && month <= 9) {
                month = "0" + month;
            }
            if (day >= 0 && day <= 9) {
                day = "0" + day;
            }
            /*if (hour >= 0 && hour <= 9) {
                hour = "0" + hour;
            }
            if (minutes >= 0 && minutes <= 9) {
                minutes = "0" + minutes;
            }
            if (seconds >= 0 && seconds <= 9) {
                seconds = "0" + seconds;
            }
            return year + "-" + month + "-" + day + " " + hour + sign2 + minutes + sign2 + seconds;*/
            return year+"-"+month+"-"+day;
        }
    },
    watch:{
        sz_ex61s:{
            handler:function(newVal){
                
                this.changeAmt();
                try{
                    if(this.isgm!="Y"){
                        this.data["szInfo"].sz_ex61=newVal;
                    }
                }catch(e){}
            }
        },
        c_ex60:{
             handler:function(newVal){
                this.changeAmt();
              
            }
        },
        value:{
            handler:function(newVal){
                this.sz_ex42=newVal;
                if(this.isgm=="Y"){
                    this.$set(this.data["gmInfo"],"c_ex71",newVal)
                }else
                    this.$set(this.data["szInfo"],"sz_ex42",newVal)
                this.isJm=true;
                this.setJm();
                this.changeAmt();
                this.$nextTick(function () {
                    // Code that will run only after the
                    // entire view has been rendered
                    this.isJm=false;
                })
            }
        },
         data:{
            handler: function (newVal) {
                try{
                    if(!this.isCheckout){
                        if(this.jmSet.length>0&&(!this.value||this.value=="无")&&!this.isJmSet){
                            console.log("开始减免判断--------------------")
                            for(let i=0;i<this.jmSet.length;i++){
                                let jmField=this.jmSet[i].jmField.split(".");
                                let jmField2=this.jmSet[i].jmField2.split(".");
                                let jmText=this.jmSet[i].jmText;
                                let jmText2=this.jmSet[i].jmText2;
                               
                                let v=this.jmSet[i].jmFieldValue;
                                console.log("减免val================"+v);
                                if(v!=this.data[jmField[0]][jmField[1]]){
                                    v=this.data[jmField[0]][jmField[1]];
                                    console.log("va==================="+v+"=="+jmText2)
                                    if(v.indexOf(jmText2)!=-1){
                                        this.isJmSet=true;
                                        //this.data[jmField2[0]][jmField2[1]]=jmText;
                                        this.$set(this.data[jmField2[0]],jmField2[1],jmText)
                                        console.log(jmField2[0]+"="+this.data[jmField2[0]][jmField2[1]]+"="+jmField2[1]+"="+jmText,"开始减免数据库是否来得及")
                                        this.value=jmText;
                                    }
                                }
                            }
                        }
                        if(this.jmSet.length>0&&(this.value&&this.value!="无")&&this.isJmSet){
                            console.log("开始减免判断2222--------------------")
                            for(let i=0;i<this.jmSet.length;i++){
                                let jmField=this.jmSet[i].jmField.split(".");
                                let jmField2=this.jmSet[i].jmField2.split(".");
                                let jmText=this.jmSet[i].jmText;
                                let jmText2=this.jmSet[i].jmText2;
                               
                                let v=this.data[jmField[0]][jmField[1]];
                                console.log("开始判断==="+v+"="+jmText2)
                                if(v.indexOf(jmText2)==-1&&this.data[jmField2[0]][jmField2[1]]==jmText){
                                    this.isJmSet=false;
                                    //this.data[jmField2[0]][jmField2[1]]="";
                                    this.$set(this.data[jmField2[0]],jmField2[1],"")
                                    this.value="";
    
                                }
                            }
                        }
                    }
                    
                }catch(e){}
                let datas=this.$refs.tableEditss.getData();
                //公墓定金问题
                this.dingjin();
                console.log()
                try{
                    if(this.data["szInfo"]["sz_depart"]){
                        this.depart=this.data["szInfo"]["sz_depart"]
                    }else if(this.exkey.departField){
                        this.depart=this.data[this.exkey.departPId][this.exkey.departField]
                       
                    }
                }catch(e){
                    try{
                        if(this.exkey.departField){
                           // alert(this.depart+"=="+this.data[this.exkey.departPId][this.exkey.departField])
                            if(this.depart&&this.depart!=this.data[this.exkey.departPId][this.exkey.departField]){
                                this.$set(this.data,this.dataField,[])
                            }
                            this.depart=this.data[this.exkey.departPId][this.exkey.departField]
                        }
                    }catch(e){}
                }

                if(this.isgm=="Y"){
                    try{
                        //console.log("this.gm_id===================================="+this.isgm+"=="+this.c_ex60+"=="+this.data["gmInfo"].c_ex60)
                        try{
                            let c_ex60=this.data["gmInfo"].c_ex60;
                            if(c_ex60!=this.c_ex60){
                                this.c_ex60=c_ex60;
                            }
                        }catch(e){}
                        let gm_dat3=this.data["gmInfo"].gm_dat3;
                        let gm_dat4=this.data["gmInfo"].gm_dat4;
                        let c_ex57=this.data["gmInfo"].c_ex57;
                        let c_ex27=this.data["gmInfo"].c_ex27;
                        let c_ex4=this.data["gmInfo"].c_ex4;
                        let c_ex10=this.data["gmInfo"].c_ex10;

                        //if(this.first=='Y'){
                            try{
                                for(let i=0;i<this.data[this.dataField].length;i++){
                                    let szi_ex7=this.data[this.dataField][i].szi_ex7;
                                    let szi_ex2=this.data[this.dataField][i].szi_ex2;
                                    if(szi_ex7=='墓型'&&szi_ex2!=c_ex10){
                                        let data=this.data[this.dataField][i];
                                        data.szi_ex2=c_ex10;
                                        data.szi_ex5=c_ex10;
                                        this.$set(this.data[this.dataField],i,data)
                                    }
                                }
                            }catch(e){}
                            
                        //}
                       // this.first='N'
                        if(c_ex4&&this.isSetGlf=='N'&&c_ex27!='Y'){
                            this.loadGlf();
                        }
                        
                        if((c_ex57==""||c_ex57=="N")&&(gm_dat3!=this.gm_dat3||gm_dat4!=this.gm_dat4)&&gm_dat3&&gm_dat4&&c_ex27!='Y'){
                             
                             let years=this.getDateYearSub(gm_dat3,gm_dat4);
                             let months=this.getDateMonthSub(gm_dat3,gm_dat4);
                             let index=-1;
                             let index_=-1;
                             let gmlType=sessionStorage.getItem("管理费单位");//根据他选择的是年还是月来选择不同的管理费
                             for(let i=0;i<this.data["item"].length;i++){
                                let szi_ex7=this.data["item"][i].szi_ex7;
                                let szi_ex3=this.data["item"][i].szi_ex3;
                                if(szi_ex7=="管理费"){
                                    index_=i;
                                }
                                if(szi_ex7=="管理费"&&szi_ex3==gmlType){
                                    index=i;
                                }
                            }
                            if(index==-1&&index_!=-1){
                                index=index_;
                            }
                           // alert(years)
                           // alert(index+"=="+years)
                            if(index>=0&&years>=0){
                                let item=this.data["item"][index];
                                if(item.szi_ex3.indexOf("月")!=-1){
                                    years=months;
                                }
                                let szi_ex2=Number(this.data["item"][index].szi_ex2);
                                this.data["item"][index].szi_ex4=years;
                                this.data["item"][index].szi_ex5=Number(years)*szi_ex2;
                                  try{
                                    this.data["gmInfo"].c_ex58=Number(years)*szi_ex2;
                                  
                                }catch(e){}
                                //this.$set(this.data["item"],index,)
                            }else if(years>0||months>0){
                                let row=null;
                                let row_bak=null;

                                 for(let i=0;i<this.sfItemData.length;i++){
                                    let szi_ex7=this.sfItemData[i].szi_ex7;
                                    let szi_ex3=this.sfItemData[i].szi_ex3;
                                    if(szi_ex7=="管理费"){
                                        row_bak=this.sfItemData[i];
                                    
                                    }
                                    if(szi_ex7=="管理费"&&szi_ex3==gmlType){
                                        row=this.sfItemData[i];
                                    
                                    }
                                }
                                if(row_bak&&!row){
                                    row=row_bak;
                                }
                                if(row){
                                    if(row.szi_ex3.indexOf("月")!=-1){
                                        years=months;
                                    }
                                    if(years>0){
                                        console.log("year================"+years)
                                        if(c_ex4){
                                            let szi_ex5=Number(years)*Number(c_ex4);
                                            if(c_ex4.indexOf(".")!=-1){
                                                let num=c_ex4.substring(c_ex4.indexOf(".")+1).length;
                                                szi_ex5=szi_ex5.toFixed(num)
                                            }
                                            row.szi_ex2=c_ex4;
                                            row.szi_ex4=years;
                                            row.szi_ex5=szi_ex5
                                        }else{
                                            let szi_ex5=Number(years)*Number(row.szi_ex2);
                                            console.log("index3====="+row.szi_ex2.indexOf(".")+"="+row.szi_ex2.substring(row.szi_ex2.indexOf(".")+1)+"="+row.szi_ex2.substring(row.szi_ex2.indexOf(".")+1).length)
                                            if(row.szi_ex2.indexOf(".")!=-1){
                                                let num=row.szi_ex2.substring(row.szi_ex2.indexOf(".")+1).length;
                                                
                                                szi_ex5=szi_ex5.toFixed(num)
                                            }
                                            row.szi_ex4=years;
                                            row.szi_ex5=szi_ex5
                                        }
                                       
                                    
                                        this.$set(this.data["item"],this.data["item"].length,row);
                                    }
                                   
                                }
                            }
                            this.gm_dat3=gm_dat3;
                            this.gm_dat4=gm_dat4;
                        }
                        if((c_ex57==""||c_ex57=="N")&&c_ex4!=this.c_ex4&&c_ex27!='Y'){
                          
                            let index=-1;
                            let index_=-1;
                            let gmlType=sessionStorage.getItem("管理费单位")
                             for(let i=0;i<this.data["item"].length;i++){
                                let szi_ex7=this.data["item"][i].szi_ex7;
                                let szi_ex3=this.data["item"][i].szi_ex3;
                                if(szi_ex7=="管理费"){
                                    index_=i;
                                }
                                if(szi_ex7=="管理费"&&gmlType==szi_ex3){
                                    index=i;
                                }
                            }
                            if(index_!=-1&&index==-1){
                                index=index_;
                            }
                            if(index>=0&&c_ex4){
                                console.log("c_ex4=================================================="+c_ex4)
                                let item=this.data["item"][index];
                                let szi_ex4=Number(this.data["item"][index].szi_ex4);
                                this.data["item"][index].szi_ex2=c_ex4;
                                this.data["item"][index].szi_ex5=Number(c_ex4)*szi_ex4;
                                 try{
                                    this.data["gmInfo"].c_ex58=Number(c_ex4)*szi_ex4;
                                  
                                }catch(e){}
                                //this.$set(this.data["item"],index,)
                            }
                            this.c_ex4=c_ex4;
                        }


                        let sz_ex42=this.data["gmInfo"].c_ex71;
                        if(sz_ex42!=this.value&&sz_ex42!=this.sz_ex42){
                            this.sz_ex42=sz_ex42;
                            this.value=sz_ex42;//减免类型变了，就会触发setJm()方法
                            
                        }
                        
                        let c_ex77=this.data["gmInfo"].c_ex77;
                        if(c_ex77!=this.c_ex77){
                            this.setJm();
                            this.c_ex77=c_ex77;
                        }
                    }catch(e){}
                }

                try{
                    if(this.data.szInfo.sz_ex135=="Y"){//全部减免
                        console.log("sz_ex1111111111111111111111111")
                        for(let i=0;i<this.data["item"].length;i++){
                            if(Number(this.data["item"][i].szi_ex5)>0){
                               
                                this.$set(this.data["item"][i],"szi_ex42","-"+this.data["item"][i].szi_ex5)
                                //console.log(this.data)
                            }
                        }
                        this.isQBjm=true;
                    }else if(this.isQBjm){
                        this.isQBjm=false;
                        for(let i=0;i<this.data["item"].length;i++){
                            if(Number(this.data["item"][i].szi_ex5)>0){
                               
                                this.$set(this.data["item"][i],"szi_ex42","")
                                //console.log(this.data)
                            }
                        }
                    }
                }catch(e){}
                try{
                    if(this.exkey.departField){
                        try{
                            let sl_depart_=this.data[this.exkey.departPId][this.exkey.departField]
                            if(this.sl_depart!=sl_depart_){
                                this.sl_depart=sl_depart_;
                                 this.$post(this.appid,this.postUrl,{gm_id:this.gm_id,depart:this.sl_depart,type3:escape(this.extype)}).then(data=>{
                                    this.sfItemData=[];
                                    for(let i=0;i<data.item.length;i++){
                                        this.sfItemData.push(data.item[i]);
                                    }
                                });
                                
                               //  this.loadJm();
                            }
                        }catch(e){}
                    }
                }catch(e){}
                try{
                    if(this.data.szInfo){
                        try{
                            let sz_depart_=this.data["szInfo"]["sz_depart"]
                            if(this.sz_depart!=sz_depart_){
                                this.sz_depart=sz_depart_;
                                 this.$post(this.appid,this.postUrl,{gm_id:this.gm_id,depart:this.sz_depart,type3:escape(this.extype)}).then(data=>{
                                    this.sfItemData=[];
                                    for(let i=0;i<data.item.length;i++){
                                        this.sfItemData.push(data.item[i]);
                                    }
                                    sessionStorage.setItem("sfItemData",JSON.stringify(this.sfItemData))
                                });
                                
                                 this.loadJm();
                            }
                        }catch(e){}
                        
                        try{
                            if(localStorage.getItem("sCode")=="hmylgbyg"){
                                if(!this.data.szInfo.sz_ex65&&this.isFirst2=="Y"){
                                    let sz_ex67=this.data.szInfo.sz_ex67;
                                    let sz_ex68=this.data.szInfo.sz_ex68;
                                    let sz_ex69=this.data.szInfo.sz_ex69;
                                    let sz_ex107=this.data.szInfo.sz_ex107;
                                    if(sz_ex67&&sz_ex68&&sz_ex69&&sz_ex107=="医院"){
                                        sz_ex68=sz_ex68=="海门市"?"海门区":sz_ex68;
                                        this.$set(this.data.szInfo,"sz_ex65",sz_ex67+sz_ex68+sz_ex69+"卫生院")
                                        this.isFirst2="N"
                                    }
                                }
                            }
                        }catch(e){}
                        let hy_ex6="";
                        try{
                            hy_ex6=this.data.szInfo.hy_ex6;
                            
                        }catch(e){}
                        
                        let carNum=this.data.szInfo.carNum;
                        let sz_ex42=this.data.szInfo.sz_ex42;
                        //20230828修改，请求次数过多
                        /*if(this.sfItemData.length==0){
                           
                            this.$post(this.appid,this.postUrl,{gm_id:this.gm_id,depart:this.depart,type3:escape(this.extype)}).then(data=>{
                                this.sfItemData=[];
                                for(let i=0;i<data.item.length;i++){
                                    this.sfItemData.push(data.item[i]);
                                }
                                if(hy_ex6)
                                    this.loadFn(hy_ex6)
                               this.loadCar(carNum)
                                
                                if(sz_ex42!=this.value&&sz_ex42!=this.sz_ex42){
                                    this.sz_ex42=sz_ex42;
                                    this.value=sz_ex42;//减免类型变了，就会触发setJm()方法
                                    
                                }
                                if(data.isPriceSelect){
                                    this.isPriceSelect=data.isPriceSelect;
                                }
                            })
                            //this.isFirstJm="N"
                            console.log("sz_ex42ss===="+this.value)
                        }else{*/

                        console.log("sfItemData=========================================");
                        if(this.sfItemData.length>0){
                            if(hy_ex6)
                                this.loadFn(hy_ex6)
                            this.loadCar(carNum)
                            console.log("this.loadFn=1111========================================"+hy_ex6);    
                        }
                        
                        console.log("this.loadFn=========================================");    
                        
                            /*if(sz_ex42!=this.value){
                                this.value=sz_ex42;//减免类型变了，就会触发setJm()方法
                                
                            }*/
                            if(sz_ex42!=this.value&&sz_ex42!=this.sz_ex42){
                                this.sz_ex42=sz_ex42;
                                this.value=sz_ex42;//减免类型变了，就会触发setJm()方法
                                
                            }
                            
                           // this.isFirstJm="N"
                            console.log("sz_ex42ss11===="+this.value)
                        //}
                    }

                }catch(e){
                    
                }
                try{
                    if(this.data.yuyue){
                        let dw_="";
                        try{
                            if(this.data["yuyue"]["sz_dw"])
                                dw_=this.data["yuyue"]["sz_dw"];
                            else
                                dw_=this.data["yuyue"]["sh_ex27"];
                        }catch(e){}
                        try{
                            if(this.dw!=dw_){
                                this.dw=dw_;
                                 this.$post(this.appid,this.postUrl,{gm_id:this.gm_id,depart:this.sz_depart,dw:this.dw,type3:escape(this.extype)}).then(data=>{
                                    this.sfItemData=[];
                                    for(let i=0;i<data.item.length;i++){
                                        this.sfItemData.push(data.item[i]);
                                    }
                                });
                                
                                 this.loadJm();
                            }
                        }catch(e){}
                    }
                }catch(e){}
                

                //里程计算
                //try{
                    console.log(this.data.szCar,"车辆============")
                    if(this.data.szCar){
                        console.log("开始计算里程===================")
                        let scr_ex10=this.data.szCar.scr_ex10;

                        let hasCar=false;
                        let carName="";
                        for(let i=0;i<this.data[this.dataField].length;i++){
                            let szi_ex9=this.data[this.dataField][i].szi_ex9;
                            if(szi_ex9=="车辆"){
                                hasCar=true;
                                carName=this.data[this.dataField][i].szi_ex1;
                            }
                        }
                        if(this.scr_ex10!=scr_ex10||!hasCar||this.carName!=carName){
                            this.scr_ex10=scr_ex10;
                            let scr_ex10i=Number(scr_ex10);
                            for(let i=0;i<this.data[this.dataField].length;i++){
                                let szi_ex9=this.data[this.dataField][i].szi_ex9;
                                //console.log(this.data[this.dataField][i].szi_ex1+"=="+szi_ex9)
                                if(szi_ex9=="车辆"){
                                    //console.log("有车辆-----------")
                                    let szi_ex49=this.data[this.dataField][i].szi_ex49;
                                    let szi_ex50=this.data[this.dataField][i].szi_ex50;
                                    let szi_ex5=this.data[this.dataField][i].szi_ex5;
                                    let sf_ex9=Number(this.data[this.dataField][i].sf_ex9);
                                    console.log("sf_ex9=========="+sf_ex9+"=="+szi_ex49+"=="+szi_ex50)
                                    if(szi_ex49&&szi_ex50){
                                        let szi_ex49i=Number(szi_ex49);
                                        let szi_ex50i=Number(szi_ex50);
                                        if(scr_ex10i>szi_ex49i){
                                            if(szi_ex49i==0){
                                                let num=scr_ex10i-szi_ex49i;
                                                let amt=sf_ex9+szi_ex50*num;
                                                console.log("scr_ex10i======"+scr_ex10i+"="+szi_ex49i+"=="+sf_ex9+"=="+szi_ex50+"=="+num)
                                                if(amt!=szi_ex5){
                                                    this.$set(this.data[this.dataField][i],"szi_ex2",szi_ex50);
                                                    this.$set(this.data[this.dataField][i],"szi_ex4",num);
                                                    this.$set(this.data[this.dataField][i],"szi_ex5",amt);
                                                }
                                            }else{
                                                let num=scr_ex10i-szi_ex49i;
                                                let amt=sf_ex9+szi_ex50*num;
                                                console.log("scr_ex10i======"+scr_ex10i+"="+szi_ex49i+"=="+sf_ex9+"=="+szi_ex50+"=="+num)
                                                if(amt!=szi_ex5){
                                                    this.$set(this.data[this.dataField][i],"szi_ex2",amt);
                                                    this.$set(this.data[this.dataField][i],"szi_ex4","1");
                                                    this.$set(this.data[this.dataField][i],"szi_ex5",amt);
                                                }
                                            }
                                            
                                           
                                        }else{
                                            if(sf_ex9!=szi_ex5){
                                                this.$set(this.data[this.dataField][i],"szi_ex2",sf_ex9);
                                                this.$set(this.data[this.dataField][i],"szi_ex4","1");
                                                this.$set(this.data[this.dataField][i],"szi_ex5",sf_ex9);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    
                //}catch(e){}
                //计算里程结束

                console.log("开始计算--------------------------------")
                console.log(this.data.lt);
                //alert(this.isComputeLt)
               if(this.data.lt&&this.isComputeLt=="Y"){
                   try{
                        
                        let lt_dat1=this.data.lt.lt_dat1;
                        let lt_dat2=this.data.lt.lt_dat2;
                        let lt_name="";
                        for(let i=0;i<datas.length;i++){
                            if(datas[i].szi_ex7=='礼厅'){
                                lt_name=datas[i].szi_ex1;
                            }
                        }

                        //console.log("2="+this.lt_dat1_old+"="+this.lt_dat2_old+"="+this.lt_name_old+"=="+lt_dat1+"=="+lt_dat2)
                        if((lt_name!=this.lt_name_old||lt_dat1!=this.lt_dat1_old||lt_dat2!=this.lt_dat2_old)&&lt_dat2!=undefined&&lt_dat1!=undefined){
                          // console.log("122222222223333333333333333333333")

                            let day=Math.ceil(this.getDaysBetween(lt_dat1,lt_dat2));
                            let hour=Math.ceil(this.getDaysBetweenHour(lt_dat1,lt_dat2));
                            let index=-1;
                            let amt=0;
                            let totalAmt=0;
                            let unit="";
                            let num=0;
                            for(let i=0;i<datas.length;i++){
                                console.log("112-------------"+datas[i].szi_ex1)
                                if(datas[i].szi_ex7=='礼厅'||datas[i].szi_ex9=='礼厅'){
                                    console.log("11-------------"+datas[i].szi_ex1)
                                    index=i;
                                    amt=datas[i].szi_ex2;
                                    unit=datas[i].szi_ex3;

                                    if(unit.indexOf("时")!=-1){
                                        totalAmt=amt*hour;
                                        num=hour;
                                    }else{
                                        totalAmt=amt*day;
                                        num=day;
                                    }
                                    console.log(this.data[this.dataField][index])
                                    console.log("index=============="+index+"="+num+"="+totalAmt)
                                    if(index!=-1){
                                        this.$set(this.data[this.dataField][index],"szi_ex5",totalAmt);
                                        this.$set(this.data[this.dataField][index],"szi_ex4",num);
                                    
                                    }

                                }
                            }

                            window.setTimeout(()=>{
                                this.lt_dat1_old=lt_dat1;
                                this.lt_dat2_old=lt_dat2;
                                this.lt_name_old=lt_name;
                            },3000)
                            
                        }
                       
                        
                        
                       
                        //this.$refs.tableEditss.setData(index,"szi_ex5",totalAmt);
                        //this.$refs.tableEditss.setData(index,"szi_ex4",num);
                    }catch(e){
                        
                    }
                   
                    
               }else if(this.data.lc){
                   
               }
               try{
                    console.log("this.isCheckout===="+this.isCheckout+"=="+this.isLcHh);
                    ////计算冷藏，连云港，会排除守灵时间；按照火化日期计算冷藏天数
                    if(!this.isCheckout&&this.isLcHh&&this.data.lc){
                    
                                
                        let lc_dat1=this.data.lc.lc_dat1;
                        let lc_dat2=this.data.szInfo.sz_dat7;
                        
                        console.log("进入冷藏====="+lc_dat1+"=="+lc_dat2)

                        let isOklc=false;
                        let ltDay=0;
                        for(let i=0;i<this.data[this.dataField].length;i++){
                                
                            if((","+this.lcName+",").indexOf(","+this.data[this.dataField][i].szi_ex1+",")!=-1){
                                console.log(this.data[this.dataField][i])
                                let num=Number(this.data[this.dataField][i].szi_ex4);
                                console.log("num========"+num+"=="+this.data[this.dataField][i].szi_ex4)
                                if(num==1){
                                    isOklc=true;
                                    
                                }
                            }
                            if(this.data[this.dataField][i].szi_ex7=="礼厅"){
                                ltDay=Number(this.data[this.dataField][i].szi_ex4)
                            }
                        }

                        let lt_dat1="";
                        try{
                            lt_dat1=this.data.lt[0].lt_dat1;
                        }catch(e){}

                        console.log("isOklc==="+isOklc+"=="+lc_dat1+"=="+lc_dat2+"=="+this.isComputeLc+"=="+ltDay)
                        if((lc_dat1!=this.lc_dat1_old||lc_dat2!=this.lc_dat2_old||isOklc)&&this.isComputeLc&&lc_dat2){
                            let day=Math.floor(this.getDaysBetween(lc_dat1.substring(0,10),lc_dat2.substring(0,10)));
                            if(lt_dat1&&ltDay){
                                let day_=Math.floor(this.getDaysBetween(lc_dat1.substring(0,10),lt_dat1.substring(0,10)));
                                console.log(day_+"=="+lc_dat1.substring(0,10)+"="+lt_dat1,"day_=======================")
                                if(day_>=0){
                                    console.log("11111111111111111111111111111111111111111111111")
                                    day=day-ltDay;
                                }
                                console.log(day,"days==============")
                            }
                            let hour=Math.floor(this.getDaysBetweenHour(lc_dat1,lc_dat2));
                            let index=-1;
                            let amt=0;
                            let totalAmt=0;
                            let unit="";
                            let num=0;
                            for(let i=0;i<this.data[this.dataField].length;i++){
                                
                                if((","+this.lcName+",").indexOf(","+this.data[this.dataField][i].szi_ex1+",")!=-1){
                                   
                                    index=i;
                                    amt=datas[i].szi_ex2;
                                    unit=datas[i].szi_ex3;

                                    if(unit.indexOf("时")!=-1){
                                        totalAmt=amt*hour;
                                        num=hour;
                                    }else{
                                        totalAmt=amt*day;
                                        num=day;
                                    }
                                    if(!num||num<=0){
                                        num="1";
                                        this.isComputeLc=false;
                                        totalAmt=amt;
                                    }
                                    if(index!=-1){
                                        this.$set(this.data[this.dataField][index],"szi_ex5",totalAmt);
                                        this.$set(this.data[this.dataField][index],"szi_ex4",num);
                                    
                                    }

                                }
                            }

                            this.lc_dat1_old=lc_dat1;
                            this.lc_dat2_old=lc_dat2;
                            
                        }
                        
                        
                        
                        
                        //this.$refs.tableEditss.setData(index,"szi_ex5",totalAmt);
                        //this.$refs.tableEditss.setData(index,"szi_ex4",num);
                    
                    }
                }catch(e){
                        
               }
                
            },      
            deep: true    //深度监听
        },
        item:{
            deep:true,
            handler:function(newV,oldV){
                // alert(this.change+"=="+this.isJm)
                this.changeAmt();
                console.log("this.change==="+this.change+"=="+this.isJm)
                if(!this.change&&!this.isJm){
                    this.changeSetJm=true;
                    this.setJm();
                    this.changeSetJm=false;
                }else{
                    this.change=false;
                }
            }
        },
        
        flower:{
            deep:true,
            handler:function(newV,oldV){
               if(this.data.szflower){
                   let amt=0;
                   let data_={};
                   for(let i=0;i<this.data.szflower.length;i++){
                       let szf_ex3=this.data.szflower[i].szf_ex3;//价格
                       let szf_ex8=this.data.szflower[i].szf_ex8;//类型,花篮，花圈
                       if(szf_ex3&&szf_ex8){
                            let num_=0;
                            let amt_=0;
                            if(data_[szf_ex8+szf_ex3]){
                                num_=data_[szf_ex8+szf_ex3].num;
                                amt_=data_[szf_ex8+szf_ex3].amt;
                            }else{
                                data_[szf_ex8+szf_ex3]={}
                            }
                            num_++;
                            amt_=amt_+Number(szf_ex3);
                            data_[szf_ex8+szf_ex3].num=num_;
                            data_[szf_ex8+szf_ex3].amt=amt_;
                            data_[szf_ex8+szf_ex3].price=szf_ex3;
                            data_[szf_ex8+szf_ex3].type=szf_ex8;
                            amt=amt+Number(szf_ex3);
                       }
                       
                   }
                   if(amt){
                       for(let key in data_){
                            let num=data_[key].num;
                            let amt=data_[key].amt;
                            let price=data_[key].price;
                            let type=data_[key].type;
                            price=price.replace(type,"")
                            let data={};
                            data.name2=type+"定制("+price+")";
                            data.name=type+"("+price+")";
                            data.num=num;
                            data.pri=price;
                            data.amt=amt;
                            data.isFg=true;
                            this.addItems(data)
                       }    
                       
                   }
                   
                   let flowerMap={};
                   for(let key in data_){
                        let num=data_[key].num;
                        let amt=data_[key].amt;
                        let price=data_[key].price;
                        let type=data_[key].type;
                        let name=type+"定制("+price+")";
                        let numtotal=0;
                        if(flowerMap[name]){
                            numtotal=flowerMap[name];
                        }
                        numtotal=numtotal+Number(num);
                        flowerMap[name]=numtotal;
                   }
                   let isOks=true;
                   while(isOks){
                        let index=-1;
                        for(let i=0;i<this.data[this.dataField].length;i++){
                            let szi_ex1=this.data[this.dataField][i].szi_ex1;
                            let szi_ex4=this.data[this.dataField][i].szi_ex4;
                            let szi_ex2=Number(this.data[this.dataField][i].szi_ex4);
                            if(flowerMap[szi_ex1]){
                                let num=flowerMap[szi_ex1];
                                if(num!=Number(szi_ex4)){
                                    this.$set(this.data[this.dataField][i],szi_ex4,num);
                                    this.$set(this.data[this.dataField][i],szi_ex5,num*szi_ex2);
                                }
                            }else if(szi_ex1.indexOf("花圈定制")!=-1||szi_ex1.indexOf("花篮定制")!=-1){
                                index=i;
                                break;
                            }
                        }
                        if(index>=0){
                            this.$delete(this.data[this.dataField],index);
                        }else{
                            isOks=false;
                        }
                        
                   }
                   
                   
               }
            }
        }
    },
     computed:{
       item(){
            return this.data.item;
       },
       flower(){
           if(this.data.szflower){
               return this.data.szflower;
           }
       }
     },
}

  
export default funeralMixin;
  